Objective c Xcode:尝试子类化NSWindowController期间未加载基于文档的应用程序窗口
我真的没有做太多,我已经被卡住了 到目前为止,我已经做了:Objective c Xcode:尝试子类化NSWindowController期间未加载基于文档的应用程序窗口,objective-c,xcode,macos,Objective C,Xcode,Macos,我真的没有做太多,我已经被卡住了 到目前为止,我已经做了: 添加了NSWindowController子类(MikesWindowController.h&.m) 从MikesDocument.m中删除了windowNibName(因为我正在实现自己的 WindowController子类。) 我试过: 测试NSLog是否会在init,窗口控制器IDLOADNIB,应用程序IDfinishLaunching返回。仅打印初始时的NSLog 并且,在编译我的文档应用程序后,测试了主菜单->文件
- 添加了NSWindowController子类(MikesWindowController.h&.m)
- 从MikesDocument.m中删除了windowNibName(因为我正在实现自己的 WindowController子类。)
- 测试NSLog是否会在init,窗口控制器IDLOADNIB,应用程序IDfinishLaunching返回。仅打印初始时的NSLog
- 并且,在编译我的文档应用程序后,测试了主菜单->文件->新建
-(void)makeWindowControllers{
MikesController *controller = [[MikesWindowController alloc]init];
[self addWindowController:controller];
}
-(id) initWithWindowNibName:(NSString *)windowNibName{
self = [super initWithWindowNibName:windowNibName];
return self;
}
-(void)makeWindowControllers{
MikesWindowController *controller =
// must tell controller which nib file to use.
[[MikesWindowController alloc]initWithWindowNibName:@"MikesDocument"];
[self addWindowController:controller];
}
经过深思熟虑,我找到了那个答案。呜呼。享受未来
- 从我的NSWindowController子类中删除了initWithWindow
- 对我的NSWindowController子类实现了initWithWindowNibName,因此现在无论何时初始化,我都必须指定窗口nibName李>
-(void)makeWindowControllers{
MikesController *controller = [[MikesWindowController alloc]init];
[self addWindowController:controller];
}
-(id) initWithWindowNibName:(NSString *)windowNibName{
self = [super initWithWindowNibName:windowNibName];
return self;
}
-(void)makeWindowControllers{
MikesWindowController *controller =
// must tell controller which nib file to use.
[[MikesWindowController alloc]initWithWindowNibName:@"MikesDocument"];
[self addWindowController:controller];
}
(下面)再次回到主文档,我更正了makeWindowController方法,并用“MikesDocument”实例化了我的控制器(对于MikesDocument.xib),并添加了它
MikesDocument.m
-(void)makeWindowControllers{
MikesController *controller = [[MikesWindowController alloc]init];
[self addWindowController:controller];
}
-(id) initWithWindowNibName:(NSString *)windowNibName{
self = [super initWithWindowNibName:windowNibName];
return self;
}
-(void)makeWindowControllers{
MikesWindowController *controller =
// must tell controller which nib file to use.
[[MikesWindowController alloc]initWithWindowNibName:@"MikesDocument"];
[self addWindowController:controller];
}
成功!甚至不用麻烦调用init或实现init,因为它随时都会返回错误