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

时间:2015-08-14 15:20:07

标签: macos window xib nswindow nswindowcontroller

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

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

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

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

1 个答案:

答案 0 :(得分:0)

您错误地使用了NSViewController的子类,即" MyViewController"。你需要的是NSWindowController的子类。作为工作表,您只能使用NSWindow(不是NSView)。如果您尝试以模态方式运行窗口(这意味着具有从属窗口),请确保显示现有窗口。

使用XIB创建NSWindowController的新子类时,没有窗口可以实现的情况。然后实例化如下:

    @interface SomeClass {
      CustomWindowController *customWindowController;
    }

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

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