Re: Correct use of NSViewController
Re: Correct use of NSViewController
- Subject: Re: Correct use of NSViewController
- From: Cathy Shive <email@hidden>
- Date: Thu, 20 Mar 2008 13:29:57 +0100
Yeah, the document. The window controller and document have a
relationship, but this isn't true for the view controllers and the
document. Again, this is part of NSViewController's ambiguous role
in this whole architecture. I don't really know how this *should* be
dealt with.
It seems like those two key paths would lead to the same thing, but
obviously some connection isn't being made the way you are
expecting. I suspect it has something to do with the fact that the
binding is being set before the view controller's view is actually
added to the view hierarchy, so that view's window isn't the window
controller's window yet which means you have no direct path to the
window controller's document at that moment.
What if you give your view controllers a reference to the window's
window controller when you create them?
Your window controller is obviously the first thing to exist. It
allocates and initializes the first view controller. If you
initialize it with a method like:
- (id)initWithWindowController:(NSWindowController*)theWindowController;
Then they could set their window controller right before they load
their nibs.
The nibs could use this keypath instead:
@"filesowner.windowController.document"
That should hook up correctly if you have a windowController ivar in
your NSViewController subclass.
On Mar 20, 2008, at 12:35 PM, Jonathan Dann wrote:
Hi Cathy,
Thanks again for your advice. I've got it working now and I'm
almost back I where I was before refactoring, I'm now running into
a bindings problem.
Before using the view controllers I had put 2 tree controllers in
my window controller's nib, 2 outline views were then bound to
these and the tree controllers themselves got their content from an
object controller that was bound to the the keypath [(Window
Controller)File's Owner].document. So the object controller was a
proxy for my document and the tree controllers had shorter keypath
to traverse to get to the array they needed in my document subclass.
Now when I do this I have the tree controllers and the document
proxy object controller in my view controller's nib. The only way I
can see to getting to the document is using the keypath
[File's Owner].view.window.windowController.document
However this does not work, seems convoluted, and I get the following:
KVO autonotifying only supports -set<Key>: methods that return
void. Autonotifying will not be done for invocations of -
[NSSplitView _setWindow:]
So my view controller needs to know about its 'owning' document
somehow and I can't see how to get it.
Have you run into this. I'm not sure getting the current document
from the document controller will work as that will change ad the
user opens more documents.
Thanks again,
Jon
P.S. Out of interest, what do you develop?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden