0
尽管我搜索并尝试了很多,但我无法启动第二个窗口。如何激活一个窗口?
我用于显示另一窗口而主窗口被激活的代码:
preferencesWindowController = (PreferencesWindowController*)[[NSWindowController alloc] initWithWindowNibName: @"Preferences"];
[preferencesWindowController showWindow: preferencesWindowController];
[[preferencesWindowController window] orderFrontRegardless];
[[preferencesWindowController window] makeKeyAndOrderFront: preferencesWindowController];
[NSApp activateIgnoringOtherApps:YES];
试图调试器后,我看到[preferencesWindowController窗口]是零
preferencesWindowController = (PreferencesWindowController*)[[NSWindowController alloc] initWithWindowNibName: @"Preferences"];
[preferencesWindowController showWindow: self];
NSWindow* window = [preferencesWindowController window]; //---> nil
为什么它无?
nib文件包含Window和PreferencesWindowController。
对不起,我用多笔错了。我遵循这个例子,它有效:http://maestric.com/doc/mac/cocoa/multiple_nibs。不要将窗口控制器添加到笔尖,而是将文件的所有者类设置为窗口控制器。
该nib文件包含Window和PreferencesWindowController。 您的代码不起作用,preferencesWindowController对象在初始化后被填充为零。 – user486134
你读过吉姆回答的第二部分了吗?您是否已将文件所有者的窗口连接到您的笔尖窗口? –
“另外,请确保您已将文件所有者的窗口连接到您的笔尖窗口。”在我的.xib中,我看到一个'文件所有者'。在连接检查员中,我可以在窗口中选择“新建参考出口”。你是这个意思吗?为什么需要它?一旦我持续参考窗口,问题就解决了,无论如何。 – isgoed