• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: difference between windowDidLoad and awakeFromNib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: difference between windowDidLoad and awakeFromNib


  • Subject: Re: difference between windowDidLoad and awakeFromNib
  • From: Ron Wilson <email@hidden>
  • Date: Wed, 17 Jul 2002 08:53:08 -0700

On Tuesday, July 16, 2002, at 10:04 PM, email@hidden wrote:

On Dienstag, Juli 16, 2002, at 06:07 Uhr, Brian Webster wrote:

On Tuesday, July 16, 2002, at 10:12 AM, cocoa-dev-
email@hidden wrote:

I'd like to know the differences between windowDidLoad in
NSWindowController and awakeFromNib.

I believe the awakeFromNib method is only called on objects that are
actually archived in the nib file. A NSWindowController is created in
code and then loads its nib file programmatically. awakeFromNib will
be called on all the objects that are loaded in the nib file, but not
the window controller, because it already exists before loading the nib.

Actually, that's not correct. If you load a nib file with [NSBundle
loadNibNamed:@"bla" owner:foo] the object specified as owner will
always (!) be sent an awakeFromNib message, even if it is already
instantiated. (That means that an object can receive this message more
than once.)

With regard to the original question my (newbie) guess is that
awakeFromNib is used by NSWindowController to set up the window
(staggering, setting the title, ...). If you override it be sure to call
[super awakeFromNib]. Therefore it is probably better to follow the
documentation and initialize your stuff in windowDidLoad.

NSNibAwaking is an informal protocol adopted by NSObject, consisting of single method, awakeFromNib. The documentation on this protocol describes exactly when and why awakeFromNib is used. On my system I found the docs at /Developer/Documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Protocols.

windowDidLoad is an instance method of NSWindowController and the docs say "Allows subclasses of NSWindowController to perform any required tasks after the window owned by the receiver has been loaded. The default implementation does nothing."

windowDidLoad is specific to NSWindowController or subclasses, is for window loading only, and will be sent to the controller only.

awakeFromNib can be implemented for any subclass of NSObject and will be sent to each object loaded from the archive (nib file) including the object specified as "File's Owner". Note that the nib's "File's Owner" does not have to be a subclass of NSWindowController.

Ron
_______________________________________________
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.

  • Prev by Date: Relaunching my app?
  • Next by Date: Re: [Seriously OT]Mac.com 60 days and counting
  • Previous by thread: Re: difference between windowDidLoad and awakeFromNib
  • Next by thread: Framework library...
  • Index(es):
    • Date
    • Thread