Re: NSWindowController subclass as nib file owner issues
Re: NSWindowController subclass as nib file owner issues
- Subject: Re: NSWindowController subclass as nib file owner issues
- From: Chris Hanson <email@hidden>
- Date: Sat, 30 Jul 2005 00:28:33 -0700
On Jul 29, 2005, at 9:28 PM, Edwin Vane wrote:
The first thing I've noticed is that
any outlets I add to NSWindowController aren't initialized by the
-initWithWindowNibName method (even though I've connected the
outlets to
the file owner in interface builder).
This is correct. (By the way, the method is named -
initWithWindowNibName: since colons are significant in method names
in Objective-C.)
What does initWithWindowNibName actuall do? The docs
lead me to believe it loads the nib file and causes all the
unarchiving stuff to
happen. What would be the purpose of loading the nib file but not
actually unarchiving the contents (which seems to be happening here)?
It doesn't necessarily load the nib file. It just allows the nib
file that the window controller will load to be specified. The
actual loading of the nib file is "lazy" so you don't pay the cost of
loading the nib and wiring up its contents until you actually need to.
NSWindowController will invoke its -windowWillLoad and -windowDidLoad
methods around window loading, so if you need to perform additional
work after a window has been loaded you can just override -
windowDidLoad.
All objects in a nib file, including the file's owner, are also sent -
awakeFromNib once the nib has been loaded and completely wired up.
This gives you another point where you can perform additional work
after loading.
Finally, an NSWindowController that's associated with an NSDocument
will invoke that document's -windowControllerWillLoadNib: and -
windowControllerDidLoadNib: methods around nib loading as well,
giving you additional control points.
Which work you should perform where is a matter of design and taste.
I tend to use -awakeFromNib only for view and connection-level
operations that I can't perform in Interface Builder, for example,
setting the double-click action of a table or outline view. I use
either the NSDocument or NSWindowController methods -- whichever is
more appropriate given what I'm trying to accomplish -- for model and
controller-level work.
-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden