objective-c - 单击按钮时无法加载窗口 nib 文件(testwindow.xib)?

标签 objective-c xcode macos cocoa

我已经创建了 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/

相关文章:

ios - 像 WhatsApp 一样,iPhone 锁定时如何添加通知标题?

php - 如何在 Mac OS X 10.5 Leopard 上设置 PEAR

macos - Bash,批量转换IP地址

iphone - 我如何引用 NSMutableArray 中的 UIButton?

ios - 使用 UI 警报 View 按钮关闭模态视图 Controller

ios - 修复了 UIPageViewController 的背景滚动效果

ios - objective c 父类(super class)中的 protected 变量在 swift 子类中不可访问

ios - SWIFT:表格 View 中的 2 个自定义单元格。怎么了?

ios - 常见的webViewDidStartLoad按类别

c# - 在 Swift 和 C# 中检测 LAN 上的多个应用程序实例