Cocoa NSBundle loadNibNamed 已弃用

Cocoa NSBundle loadNibNamed deprecated

我正在开发一个 Cocoa 应用程序,我注意到 NSBundle loadNibNamed 已被弃用。

我正在尝试使用 Sheet 来显示一些配置选项。我正在使用 AppController,Config Sheet 是单独创建的 NIB。

这是我的代码。

- (IBAction)showConfig:(id)sender{

   if (!_config) {
      [NSBundle loadNibNamed:@"Config" owner:self];
   }
   [NSApp beginSheet:self.config modalForWindow:[[NSApp delegate] window] modalDelegate:self didEndSelector:NULL contextInfo:NULL];
}

使用该代码,配置 Sheet 完美打开和关闭。

当我将此 [NSBundle loadNibNamed:@"Config" owner:self]; 切换为 [[NSBundle mainBundle] loadNibNamed:@"Config" owner:self topLevelObjects:nil]; 时,配置 Sheet 仍然可以正常工作。

我真正的问题是什么时候想关闭它。应用程序崩溃并抛出此错误:

Thread 1:EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

这是我关闭配置的 IBAction Sheet。

- (IBAction)closeConfig:(id)sender{
   [NSApp endSheet:self.config];
   [self.config close];
   self.config = nil;
}

跳过已弃用的行后,我需要做什么才能正确关闭配置 sheet?

我 运行 Yosemite 和 Xcode 6.4.

window 属性 是否在您的应用委托 class weak 中?如果是这样,请参阅 。您现在使用的未弃用方法要求您的控制器对顶级对象具有强引用。