Reputation: 1019
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?
Upvotes: 0
Views: 353
Reputation: 28242
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;
}
Upvotes: 3