gpt4 book ai didi

objective-c - NSWindowController 显示窗口 :nil does nothing

转载 作者:太空狗 更新时间:2023-10-30 03:24:56 26 4
gpt4 key购买 nike

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

  • 我的窗口 Controller :KRAuthenticationWindowController
  • 接口(interface)生成器文件:AuthenticationWindow.xib
  • 文件的所有者是 KRAuthenticationWindowController
  • window socket 连接到窗口
  • 窗口的委托(delegate)连接到文件的所有者
  • 窗口的Visible at launch 未选中
  • 窗口的关闭时释放也未选中

我的代码如下:

// 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 显示窗口 :nil does nothing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15053211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com