Xcode 7 警告 loadNibNamed:owner 已弃用:首先在 OS X 10.8 中弃用
Xcode 7 warning loadNibNamed:owner is deprecated: first deprecated in OS X 10.8
首先,这个问题是针对 Xcode 在 Objective-C 中为 Mac OSX 应用程序编写的项目。
我收到以下行的警告 "loadNibNamed:owner is deprecated: first deprecated in OS X 10.8":
[NSBundle loadNibNamed:@"StartMyDialog" owner:self];
然而,它现在似乎仍然可以正常工作。经过一番谷歌搜索后,我找到了以下解决方案:
[[NSBundle mainBundle] loadNibNamed:@"StartMyDialog" owner:self topLevelObjects:nil];
这消除了警告,但是当我 运行 我的项目时,nib 视图没有出现,即使上述行 returns TRUE 表明 nib 文件已成功加载。我还需要做些什么才能让它出现吗?谢谢。
来自 NSBundle 文档:
Discussion
Unlike legacy methods, the objects adhere to the standard cocoa memory management rules; it is necessary to keep a strong reference to them by using IBOutlets or holding a reference to the array to prevent the nib contents from being deallocated.
Outlets to top-level objects should be strong references to demonstrate ownership and prevent deallocation.
所以你需要让你的顶级对象像这样强大:
@property (nonatomic, strong) IBOutlet NSWindow *window;
首先,这个问题是针对 Xcode 在 Objective-C 中为 Mac OSX 应用程序编写的项目。
我收到以下行的警告 "loadNibNamed:owner is deprecated: first deprecated in OS X 10.8":
[NSBundle loadNibNamed:@"StartMyDialog" owner:self];
然而,它现在似乎仍然可以正常工作。经过一番谷歌搜索后,我找到了以下解决方案:
[[NSBundle mainBundle] loadNibNamed:@"StartMyDialog" owner:self topLevelObjects:nil];
这消除了警告,但是当我 运行 我的项目时,nib 视图没有出现,即使上述行 returns TRUE 表明 nib 文件已成功加载。我还需要做些什么才能让它出现吗?谢谢。
来自 NSBundle 文档:
Discussion
Unlike legacy methods, the objects adhere to the standard cocoa memory management rules; it is necessary to keep a strong reference to them by using IBOutlets or holding a reference to the array to prevent the nib contents from being deallocated.
Outlets to top-level objects should be strong references to demonstrate ownership and prevent deallocation.
所以你需要让你的顶级对象像这样强大:
@property (nonatomic, strong) IBOutlet NSWindow *window;