Re: awakeFromNib and windowWillLoad : basic question
Re: awakeFromNib and windowWillLoad : basic question
- Subject: Re: awakeFromNib and windowWillLoad : basic question
- From: Chris Hanson <email@hidden>
- Date: Fri, 4 Jul 2003 13:24:11 -0500
They're three different messages sent at three different times for
three different purposes.
(You mentioned -windowWilLoad in your subject, but your message talks
about -windowDidLoad. They're different. People, please try to write
with a little more precision. Sometimes things that look like subtle
differences are extremely important.)
*** -awakeFromNib
Any object instantiated in a nib file is sent -awakeFromNib once it has
been instantiated and all outlet & action connections made.
The object that owns the nib file, represented by "File's Owner" in
Interface Builder and the owner argument in -loadNibNamed:owner:, is
treated as if it were instantiated in the nib file and also sent
-awakeFromNib at the same time as the objects instantiated in the nib
file.
In an -awakeFromNib method you typically finish whatever set-up you
couldn't do in the nib file. One example of this would be to set a
table view's double-click action.
*** -windowWillLoad and -windowDidLoad
Before a window controller (an instance of an NSWindowController
subclass) loads its window, it sends itself -windowWillLoad so
subclasses can do whatever preparation they need in advance of window
loading. The default implementation in NSWindowController does nothing.
After a window controller (an instance of an NSWindowController
subclass) loads its window, it sends itself -windowDidLoad so
subclasses can do things like put appropriate values in controls. The
default implementation in NSWindowController does nothing.
Note that I said "loads its window." The window controller has to be
the object doing the loading, in response to -loadWindow or something
that sends -loadWindow (like -showWindow:). I don't believe setting
the window to display on launch will be sufficient, since the window
controller won't know that its window has been displayed.
*** The difference
I prefer to use -awakeFromNib only to finish configuring controls
themselves, while I prefer to populate them in -windowDidLoad (or its
NSDocument equivalent). Why? Because they're conceptually two
different thing. The first is essentially to make up for a lack of
Interface Builder palettes to finish configuring your view objects --
for instance, being able to set an NSTableView's double-click action,
or configuring a data cell for a table column -- while the second
involves gluing your model objects to your view objects.
Also, note that you can use NSWindowController in non-document
applications just as well as document-based applications. It's easier
than rolling your own.
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.