Xcode:在尝试子类化NSWindowController时,未加载基于文档的应用程序窗口

时间:2013-04-19 18:59:49

标签: objective-c xcode macos

我真的没有做太多事情,而且我已经陷入困境。

到目前为止我已经完成了:

  • 添加 NSWindowController 子类( MikesWindowController.h & .m)

  • MikesDocument.m 中删除 windowNibName (因为我正在实施自己的 WindowController子类。)

我试过了:

  • 如果NSLog将返回 init windowControllerDidLoadNib applicationDidFinishLaunching ,则进行测试。只有init的NSLog打印出来。

  • 并测试主菜单 - > 文件 - >编译我的文档应用程序后

我是否正确实施此权利?谢谢。任何建议都会很棒!在 MikesDocument.m

-(void)makeWindowControllers{
    MikesController *controller = [[MikesWindowController alloc]init];
    [self addWindowController:controller];

}

1 个答案:

答案 0 :(得分:0)

经过深思熟虑,我找到了答案。哇噢。享受未来。

  • 从我的NSWindowController子类中删除 initWithWindow
  • initWithWindowNibName 实现到我的NSWindowController子类,所以现在我初始化时,必须指定窗口nibName。

下面我在NSWindowController子类中实现了 initWithWindowNibName ,看看它是什么样的:

<强> MikesWindowController.m

-(id) initWithWindowNibName:(NSString *)windowNibName{
    self = [super initWithWindowNibName:windowNibName];
    return self;
}

(下)再回到主文档,我更正了 makeWindowController 方法,并使用&#34; MikesDocument&#34; (对于MikesDocument.xib)实例化我的控制器并添加它。

<强> MikesDocument.m

-(void)makeWindowControllers{  
    MikesWindowController *controller = 
        // must tell controller which nib file to use. 
        [[MikesWindowController alloc]initWithWindowNibName:@"MikesDocument"];  
        [self addWindowController:controller]; 

   }

成功!不要打扰调用init或实现init,因为它随时会返回错误。