和标题一样,[myWindowController showWindow:nil]
不起作用。这里有您需要知道的一些事实:NSWindowController showWindow:nil什么都不做
- 我的窗口控制:
KRAuthenticationWindowController
- 界面生成文件:
AuthenticationWindow.xib
- 文件的所有者是
KRAuthenticationWindowController
window
出口连接到窗口- 窗口的
delegate
连接到文件的所有者 - 窗口的
Visible at launch
未选中 - 窗口的
Release when closed
也选中
我的代码如下介绍:
// KRApplicationDelegate.m
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
NSLog(@"%s",__PRETTY_FUNCTION__);
KRAuthenticationWindowController *authWindowController = [[KRAuthenticationWindowController alloc] init];
[authWindowController showWindow:nil];
[[authWindowController window] makeKeyAndOrderFront:nil];
}
// KRAuthenticationWindowController.m
- (id)init {
self = [super initWithWindowNibName:@"AuthenticationWindow"];
if(!self) return nil;
NSLog(@"%s",__PRETTY_FUNCTION__);
return self;
}
- (void)loadWindow {
[super loadWindow];
[self.window setBackgroundColor:[NSColor colorWithDeviceWhite:0.73 alpha:1]];
NSLog(@"%s",__PRETTY_FUNCTION__);
}
- (void)windowDidLoad {
[super windowDidLoad];
NSLog(@"%s",__PRETTY_FUNCTION__);
}
- (void)showWindow:(id)sender {
[super showWindow:sender];
NSLog(@"%@",self.window);
NSLog(@"%s",__PRETTY_FUNCTION__);
}
我的控制台输出:
2013-02-24 16:21:45.420 Application[3105:303] -[KRApplicationDelegate applicationDidFinishLaunching:]
2013-02-24 16:21:45.421 Application[3105:303] -[KRAuthenticationWindowController init]
2013-02-24 16:21:45.428 Application[3105:303] -[KRAuthenticationWindowController loadWindow]
2013-02-24 16:21:45.428 Application[3105:303] -[KRAuthenticationWindowController windowDidLoad]
2013-02-24 16:21:45.556 Application[3105:303] <NSWindow: 0x10016e860>
2013-02-24 16:21:45.556 Application[3105:303] -[KRAuthenticationWindowController showWindow:]
我想我只是缺少一些重要的东西。任何帮助,将不胜感激。
也许你有这个问题中描述的问题http://stackoverflow.com/questions/3539721/nswindowcontroller-loadwindow-loads-window-from-nib-but-showwindow-does-nothin – sergeyne 2013-02-24 18:30:40
不,不是这样。 – akashivskyy 2013-02-24 22:08:59