• 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
awakeFromNib and File's Owner
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

awakeFromNib and File's Owner


  • Subject: awakeFromNib and File's Owner
  • From: Mark Trombino <email@hidden>
  • Date: Mon, 13 Dec 2004 10:45:46 -0800

Hello,

I'm porting an old NEXSTEP app I wrote to OS X and in the process I'm cleaning up some problems that the app has always had. One of the problems turned out to have been because awakeFromNib is getting sent twice to the same object. This object is instantiated in a nib file, and then later loads other nib files as the File's Owner. I've done some searching on this and other forums and have discovered that this is correct behavior, but I don't understand why...

In my mind, an object should only be sent awakeFromNib once and only when the object is instantiated in a nib file. I've always considered the File's Owner to be external to the nib file, since it is the object that is loading that file or at least already part of the application. There seems to be no good reason why it should be sent an awakeFromNib since it is already part of the app. Even if the File's Owner isn't the object loading the code, but instead a different object, it would seem that it still is already part of the app and is already "awake".

When I encounter a problem like this I usually discover that there are really good reasons why it is the way it is. I'm more curious than anything to find out why having the File's Owner sent an awakeFromNib is the right thing to do. Can anyone explain that to me? I obviously have the wrong idea of what awakeFromNib is for!

Possible workarounds include moving the code out of awakeFromNib and into an init method. However, I need to make sure all objects have been instantiated before doing some of the things I'm doing in awakeFromNib. That's why the code was there in the first place. A second workaround is to use a flag to see if awakeFromNib has already been executed. A third might be to wait for a NSBundleDidLoadNotification, check to see what classes were loaded, and do the appropriate thing. Are there any other solutions?

Incidentally, this behavior existed even back in NEXTSTEP days.

Thanks!

Mark

_______________________________________________
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


  • Follow-Ups:
    • Re: awakeFromNib and File's Owner
      • From: Guy English <email@hidden>
  • Prev by Date: Re: Best way to email html?
  • Next by Date: Re: c++ exceptions causing abort
  • Previous by thread: Re: About efficiently reading and writing files...
  • Next by thread: Re: awakeFromNib and File's Owner
  • Index(es):
    • Date
    • Thread