objective-c – NSWindowController showWindow:nil什么也不做

标题一样,[myWindowController showWindow:nil]不起作用.以下是您可能需要了解的一些事实:

>我的窗口控制器:KRAuthenticationWindowController
>界面构建器文件:AuthenticationWindow.xib
>文件的所有者是KRAuthenticationWindowController
窗口出口连接到窗口
>窗口的代表连接到文件的所有者
>启动时的窗口可见未被选中
>关闭时的窗口释放也被取消选中

我的代码如下:

// 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转换为实例变量.目前,它是一个局部变量.当局部变量消失时,窗口控制器可能会被释放,窗口被释放,所以它不会被显示出来.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...