如果您的应用程序要支持 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];
}
如果您真的想使用topLevelObjects:&array
Mountain Lion +,并且还想支持 Lion,那么对于 Lion 条件 (我可能错了这个)。我得到的印象loadNibNamed:owner:topLevelObjects:
是为了取代这个而创造的。
我还在其他地方读到过,当使用较新loadNibNamed:owner:topLevelObjects:
的工作表时,您应该取消选中工作表(窗口)的“关闭时释放”。关闭工作表时应注意这一点:
[self.sheet close];
self.sheet = nil;
如果您打开一个非模态窗口,我不确定应该对该复选框做什么。有任何想法吗?