我已经创建了 tabview cocoa 应用程序并具有 xib 文件名“MainMenu.xib”。还在 MainMenu.xib 文件中插入了一个按钮。现在我创建了一个具有 xib 文件名(testwindow.xib)的窗口。现在我想当我单击按钮时应该弹出测试窗口。我试过像 在Appdelegate.mm
中-(IBAction)hellobtn:(id)sender
{
NSWindowController *hellocontroller = [[NSWindowController alloc] initWithWindowNibName:@"testwindow.xib"];
[hellocontroller showWindow:self];
NSLog(@"Windows=%@", [hellocontroller window]);
代码编译成功。但是当我单击按钮时,输出窗口中会生成以下错误:
[NSWindowController loadWindow]: failed to load window nib file 'testwindow.xib'.
windows(null) //NSLog output
谁能告诉我如何从 appdelegate.mm 文件启动另一个窗口。
谢谢
最佳答案
加载 Nib 时,不应在名称中添加扩展名。
像这样:
NSWindowController *hellocontroller = [[NSWindowController alloc] initWithWindowNibName:@"testwindow"];
关于objective-c - 单击按钮时无法加载窗口 nib 文件(testwindow.xib)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30500587/