• 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: Multiple NIBs and -awakeFromNib problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple NIBs and -awakeFromNib problems


  • Subject: Re: Multiple NIBs and -awakeFromNib problems
  • From: Kurt Revis <email@hidden>
  • Date: Mon, 27 Aug 2001 16:49:37 -0700

following some of hints from apple and from the Learning Cocoa book for supporting multiple-nib apps, i'm having a problem with -awakeFromNib being called twice for my controller object.

in my main nib, i have an instance of MyController, a subclass of NSWindowController. I can understand why -awakeFromNib gets called on this controller.

You probably don't want an instance of this class in the main nib. Generally, your NSWindowController subclass is created via code, not in a nib. I'm not sure exactly who is responsible for doing this in your case (sorry, I don't have the book)...

however, when i choose a menu item calls MyController's -showWindow, MyController's -awakeFromNib gets called AGAIN. Note that MyController is NOT instantiated in the MyController.nib file, but MyController set as the File's Owner's class, as is required.

What is probably happening is that another instance of MyController is getting created. You can check this by putting this line in -awakeFromNib:
NSLog("MyController awakeFromNib, self is %p", self);

You should see two different hex values, indicating that two different instances of MyController are being used.

The docs (NSNibAwaking.html) are somewhat unclear on this point--they start out saying that awakeFromNib gets called on the objects instantiated in the nib, but later on they mention that it gets called on the file's owner as well. See the paragraph starting "Typically, awakeFromNib is implemented for classes whose instances are used as the owners of a loaded nib file (shown as "File's Owner" in Interface Builder)."

Hope this helps.

--
Kurt Revis
email@hidden


  • Follow-Ups:
    • Re: Multiple NIBs and -awakeFromNib problems
      • From: Henri Lamiraux <email@hidden>
References: 
 >Multiple NIBs and -awakeFromNib problems (From: Jeffrey J Barbose <email@hidden>)

  • Prev by Date: Re: Multiple NIBs and -awakeFromNib problems
  • Next by Date: Re: Multiple NIBs and -awakeFromNib problems
  • Previous by thread: Re: Multiple NIBs and -awakeFromNib problems
  • Next by thread: Re: Multiple NIBs and -awakeFromNib problems
  • Index(es):
    • Date
    • Thread