Re: Core Data App With Auxiliary Panel
Re: Core Data App With Auxiliary Panel
- Subject: Re: Core Data App With Auxiliary Panel
- From: Quincey Morris <email@hidden>
- Date: Sat, 1 Aug 2009 10:15:23 -0700
On Aug 1, 2009, at 07:03, Richard Somers wrote:
It is an inspector panel. One panel for many documents.
This is a crucial piece of information which changes the nature of the
problem to be solved. You gotta tell us the relevant information up
front. :)
If I create the inspector panel in the document nib and bind the
array controller to the File's Owner everything works great. It is
when I try to create an inspector panel in a separate nib that
something goes wrong. The error message "Cannot perform operation
without a managed object context" indicates the binding is not
working. I think this is my problem.
Er, no. You want one inspector for all documents, so loading a new
panel for each document is simply not the answer.
On Aug 1, 2009, at 09:32, Richard Somers wrote:
Upon further investigation I have discovered that my window
controller -document method returns nil. So as far as the binding is
concerned I have no document and no managed object context. I
thought the -document method would automatically return a pointer to
my persistent document but that is not the case.
Yes, that's what I said earlier. Excuse me for being facetious, but
when you say "automatically" you mean "magically", and there's no
magic here. The "document" property of a window controller gets set to
a non-nil value *because and only because* the window controller is
added to the list of the document's window controllers. (See
[NSDocument addWindowController:].) Otherwise, the window controller
is freestanding, and if it wants some document's object pointer (or
the document's managed object context pointer) it has to use a
different strategy.
So how do I get my NSWindowController subclass -document method to
return a pointer to my persistent document?
In your scenario, you don't. Your panel needs to switch from document
to document over time, so forget about [self document] in its window
controller.
What you want is for the inspector to reflect the state of the
*frontmost* document window -- that is, the current "main" window. So,
one strategy is to override 'windowDidBecomeMain:' and/or
'windowDidResignMain:' in your document window controller, and have
the document window controller message the panel's window controller
directly (which is a singleton and therefore can be referenced via a
static variable, or via an instance variable of the app delegate).
Another strategy is for the panel window controller to register itself
as an observer of *all* NSWindowDidBecomeMain and
NSWindowDidResignMain notifications, and to switch itself based on the
notifying window. (You can get the window out of the NSNotification
object, and use '[[[window windowController] document] isKindOfClass:
[MyDocument class]]' to find out whether the window is one of your
document windows.)
HTH
_______________________________________________
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