• 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 invocations of awakeFromNib on a single instance?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple invocations of awakeFromNib on a single instance?


  • Subject: Re: Multiple invocations of awakeFromNib on a single instance?
  • From: Vince DeMarco <email@hidden>
  • Date: Thu, 24 Jan 2002 14:44:52 -0800

On Thursday, January 24, 2002, at 12:37 PM, Evan Coyne Maloney wrote:

I seem to be experiencing some odd (or at least undocumented) behavior with the awakeFromNib message.

First, the background:

I have two NIB files. One is my main NIB, MainMenu.nib. Another is a NIB (ParseRules.nib) that contains an ancillary view (ParseRulesCriterionView)
, which may be loaded multiple times and added as subviews to a window (ParserWindow) defined in MainMenu.nib.

Further, I have a controller (ParseWindowController) for ParserWindow that is instantiated in MainMenu.nib; I am using ParseWindowController as the File's Owner for ParseRules.nib.

Within ParseRules.nib, I have another controller (ParseRulesController) that has an outlet to File's Owner, which is set to be of the class ParseWindowController.

(The way my program works, the user sets parsing rules by selecting controls in the ParseRulesCriterionView. Whenever one criterion is set, my program loads the ParseRules.nib to get a new set of controls, allowing the user to set more criteria if desired. Each noew ParseRulesCriterionView that gets loaded is added as a subview immediately below the previous criterion.)

I am sending the following message from within my ParseWindowController whenever I need to load another instance of the ParseRules.nib file:

[NSBundle loadNibNamed:PARSERULES_NIB owner:self];

(In other words, the "self" refers to my instance of ParseWindowController,
of which there is only one.)

What I'm noticing is that my ParseWindowController instance is receiving an awakeFromNib message whenever it loads ParseRules.nib, even though ParseWindowController is not instantiated in ParseRules.nib; it is ONLY defined as the "File's Owner" for ParseRules.nib. The controller within ParseRules.nib, ParseRulesController, DOES have an outlet to ParseWindowController.

From what I understand, awakeFromNib is ONLY called on an instance when that instance is decoded from the NIB; I have NOT seen anything indicating that awakeFromNib will ALSO be called on an instance that's acting as a File's Owner when loading another NIB.

Have I found a bug? Or is awakeFromNib supposed to be called in this fashion?

This is not a bug, but the correct behavior of awakeFromNib.


If this IS the correct behavior of awakeFromNib, is there another message I can handle if I want to do one-time initialization when an object is decoded from the NIB? (I am currently allocating NSMutableArrays within my awakeFromNib, and this is causing a problem, since my arrays are getting overwritten when the second awakeFromNib is sent. Obviously, I can create a flag along the lines of "alreadyAllocatedArrays" to work around this, but I'd rather understand what's really going on before I hack around the problem.)

Thanks in advance for your insight!

Why don't you check if the arrays are already allocated and don't allocate them again??

if the instance variable is == nil then don't reinitialize it.

vince


References: 
 >Multiple invocations of awakeFromNib on a single instance? (From: Evan Coyne Maloney <email@hidden>)

  • Prev by Date: Re: reestablishing IBOutlets from initWithCoder ?
  • Next by Date: Re: Permission madness
  • Previous by thread: Multiple invocations of awakeFromNib on a single instance?
  • Next by thread: Re: Multiple invocations of awakeFromNib on a single instance?
  • Index(es):
    • Date
    • Thread