就像标题中一样,[myWindowController 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:]
我想我只是错过了一些重要的东西。任何帮助,将不胜感激。
最佳答案
尝试将authWindowController转换为实例变量。当前,它是一个局部变量。当局部变量消失时,窗口 Controller 可能会被释放,并且带有它的窗口也不会被显示。
关于objective-c - NSWindowController showWindow :nil does nothing,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15053211/