在 OS X >= 10.10(插件模板)中显示 window?

Show window in OS X >= 10.10 (plugin template)?

有很多类似的问题,但它们似乎太旧了 - 没有任何反应,beginSheet:... 方法未声明等等。我需要类似以下的内容(但 window 在 OS X):

//just created class with option "also create xib"
MyViewController *vc = [[MyViewController alloc] initWithNibName:@"..." bundle:nil];
[self.navigationController pushViewController:controller animated:NO];

因此,例如,我通过类似的方式和 运行 [NSApp beginSheet:...] 使用 xib 创建 NSWindowController,但它落在任何来自 beginSheet:... 的方法上。但是这个例子甚至在苹果文档中都有描述。

我做错了什么?是不是因为我使用了通过 Alcatraz 下载的插件模板,它从一开始就没有任何 window 但应该在菜单项点击时显示它?

您错误地使用了 NSViewController 的子类,即 "MyViewController"。您需要的是 NSWindowController 的子类。作为 sheet,您只能使用 NSWindow(不能使用 NSView)。如果您尝试 运行 window 模态(这意味着依赖 window),请确保显示现有的 window。

没有 window 的情况可以通过使用 XIB 创建 NSWindowController 的新子类来实现。然后像这样实例化:

    @interface SomeClass {
      CustomWindowController *customWindowController;
    }

    - (IBAction)createNewWindow:(id)sender {
      customWindowController = [[CustomWindowController alloc] initWithWindowNibName:@"NameOfXib"];
      [customWindowController showWindow:nil];
    }

有关 sheet 的更多信息:Using Application-Modal Dialogs