mas*_*eth 15 macos xcode cocoa objective-c appkit
我发现NSBundle中的NSNibLoading方法:
+[NSBundle loadNibFile:externalNameTable:withZone:]
+[NSBundle loadNibNamed:owner:]
-[NSBundle loadNibFile:externalNameTable:withZone:]
Run Code Online (Sandbox Code Playgroud)
已经在10.8中被标记为已弃用 - 在10.8及更高版本中加载笔尖的正确方法是什么?
我想在我的应用程序创建一个自定义纸张,我必须创建NSWindowController具有initWithWindowNibName自定义纸张?
小智 13
如果您的应用程序将支持Lion,则loadNibNamed:owner:topLevelObjects:不会触发,并且在Lion上运行时您将获得异常(无法识别的选择器).经过一番搜索,我想出了这个:
// loadNibNamed:owner:topLevelObjects was introduced in 10.8 (Mountain Lion).
// In order to support Lion and Mountain Lion +, we need to see which OS we're
// on. We do this by testing to see if [NSBundle mainBundle] responds to
// loadNibNamed:owner:topLevelObjects: ... If so, the app is running on at least
// Mountain Lion... If not, then the app is running on Lion so we fall back to the
// the older loadNibNamed:owner: method. If your app does not support Lion, then
// you can go with strictly the newer one and not deal with the if/else conditional.
if ([[NSBundle mainBundle] respondsToSelector:@selector(loadNibNamed:owner:topLevelObjects:)]) {
// We're running on Mountain Lion or higher
[[NSBundle mainBundle] loadNibNamed:@"NibName"
owner:self
topLevelObjects:nil];
} else {
// We're running on Lion
[NSBundle loadNibNamed:@"NibName"
owner:self];
}
Run Code Online (Sandbox Code Playgroud)
如果你真的想要使用topLevelObjects:&arrayMountain Lion +,并且你也想支持Lion,看起来你需要依赖于loadNibFile:externalNameTable:withZone :(可用作类和实例方法)用于Lion条件(我可能错了这个).我得到的印象loadNibNamed:owner:topLevelObjects:是为了取代这个而创建的.
我还在其他地方读到,当使用较新的loadNibNamed:owner:topLevelObjects:工作表时,你应该取消选中工作表(窗口)的"关闭后释放".关闭工作表时应该注意这一点:
[self.sheet close];
self.sheet = nil;
Run Code Online (Sandbox Code Playgroud)
如果你打开一个非模态窗口,我不确定应该对该复选框做些什么.有任何想法吗?
| 归档时间: |
|
| 查看次数: |
6445 次 |
| 最近记录: |