开发者

Strange loadNibNamed behaviour

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 expe开发者_如何转开发cted behaviour? How can I suppress it?


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜