NSWindowController showWindow:刷新窗口 [英] NSWindowController showWindow: flashes the window

查看:118
本文介绍了NSWindowController showWindow:刷新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图像这样打开一个新的NSWindow:

So I'm trying to open a new NSWindow like so:

NSWindowController *winCon = [[NSWindowController alloc] initWithWindowNibName:@"NewWindow"];
[winCon showWindow:self];

执行此操作时,新窗口将在屏幕上闪烁,如其出现然后迅速消失.我知道我的窗口已在IB和所有内容中正确引用.就像它想显示窗口一样,但是随后它立即被释放或变得很奇怪.任何帮助将不胜感激.

When I do this, the new window flashes on the screen, as in it appears and then quickly disappears. I know that I have my window correctly referenced in IB and everything. It's like it wants to show the window, but then it gets deallocated or something weird almost immediately. Any help will be appreciated.

推荐答案

首先,初始化程序的名称不是-initWithNibName:,而是-initWithWindowNibName:.

First, the name of the initializer isn't -initWithNibName:, but -initWithWindowNibName:.

第二,如果您使用的是ARC,这是正确的,因为您对NSWindowController的实例没有强大的参考,因此窗口变得模糊了.该方法结束后,您的引用也将结束.

Second, and this is true if you're using ARC, your window goes foom because you don't have a strong reference for your instance of NSWindowController. When the method ends, so does your reference.

例如,如果要在应用程序委托接口中执行此操作,则:

If, say, you were to do this instead in your application delegate interface:

@property(strong) NSWindowController *winCon;

并将其合成到您的实现文件中:

And synthesized it in your implementation file:

@synthesize winCon;

然后您可以这样设置:

self.winCon = [[NSWindowController alloc] initWithWindowNibName:@"NewWindow"];
[self.winCon showWindow:self];

现在您的窗口不会消失.当应用程序关闭时,窗口控制器将被释放.

Now your window won't disappear. The window controller will be released when the application closes.

这篇关于NSWindowController showWindow:刷新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆