c. A couple of weeks ago on this list, one of our Apple experts (Luke, maybe, but I can't remember for sure) said to use the more specialized method (such as 'windowDidLoad') *instead of* the generic 'awakeFromNib', if the class has it.

I missed that thread. Do you happen to know some keywords from the subject?

While I was looking for this thread, I found this old answer from an other Cocoa expert (Chris Hanson):

http://lists.apple.com/archives/cocoa-dev/2003/Jul/msg00260.html

I'm quoting the conclusion:

“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."

Another reason to prefer a method like viewDidLoad, or windowDidLoad to awakeFromNib is that awakeFromNib can potentially be called twice on the same object. For example, if you have a window controller, and that window controller loads its main NIB file, it will get an awakeFromNib message. If that window controller later manually loads a second nib file, to present a sheet for example, it will have awakeFromNib sent to it a second time since it's the file's owner of the NIB file. This second awakeFromNib invocation usually comes as a surprise.

I recommend using awakeFromNib to do things like configure an object that awakes from a nib, but doesn't care which particular NIB it is. For example, if I had a MyView, and I represented it in nib files with a "Custom View", and I want them all to start out with their enabled boolean set to YES, I would implement awakeFromNib on MyView to set the property to YES. Now, if one of my specific windows controllers had a NIB with an instance of MyView in it, and it wanted that instance to be initially disabled, I would configure that in the window controller's windowDidLoad method.

Jon Hess

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to