【问题标题】:Show window in OS X >= 10.10 (plugin template)?在 OS X >= 10.10(插件模板)中显示窗口?
【发布时间】:2015-08-14 15:20:06
【问题描述】:

有很多类似的问题,但它们似乎太老了 - 什么都没有发生,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 下载的插件模板,它从一开始就没有任何窗口,但应该在菜单项单击时显示它?

【问题讨论】:

    标签: macos window xib nswindow nswindowcontroller


    【解决方案1】:

    您错误地使用了 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-21
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多