0

I have a document-based Cocoa app. During runtime, I load an additional nib from the bundle by invoking [NSBundle loadNibNamed:@"inspectorNIB" owner:self] (where self is the NSDocument).

Strangely enough, while loading the bundle succeeds, it invokes the NSDocument's awakeFromNib method again, causing an unnecessary second initialisation. Is this expected behaviour? How can I suppress it?

Marcel Hansemann
  • 1,019
  • 8
  • 11

1 Answers1

3

Yes, -awakeFromNib is called for each nib that's loaded if the object is referenced in the nib. If you want to avoid doing setup twice, you can set a BOOL instance variable and do a check:

if (!alreadyDidNibLoadStuff) {
    // do nib load stuff
    alreadyDidNibLoadStuff = YES;
}
Wevah
  • 28,182
  • 7
  • 83
  • 72