【问题标题】:failed to load window nib file (testwindow.xib) when click on button?单击按钮时无法加载窗口 nib 文件(testwindow.xib)?
【发布时间】:2015-05-28 08:01:51
【问题描述】:

我已经创建了 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 文件启动另一个窗口。

谢谢,

【问题讨论】:

    标签: objective-c xcode macos cocoa


    【解决方案1】:

    加载 nib 时,不应在名称中添加扩展名。

    像这样:

    NSWindowController *hellocontroller = [[NSWindowController alloc] initWithWindowNibName:@"testwindow"];
    

    【讨论】:

    • 另外,您正在调用 [hellocontroller showWindow:self];其中 self 是 AppDelegate,如果您按照您的说明从 AppDelegate 调用它
    【解决方案2】:

    固定的,

    我已经定义了 NSWindowController *hellocontroller;下面是主类的实现;

    然后我写了按钮操作:

    hellocontroller = [[NSWindowController alloc] initWithWindowNibName:@"testwindow"];
    [hellocontroller showWindow:self]; //optional, without this line, it is also running.
    

    【讨论】:

    • 很好,很高兴帮助您加载 Xib :)
    猜你喜欢
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    相关资源
    最近更新 更多