为什么我必须在我的NSWindowController上调用showWindow两次在10.5? [英] Why do I have to call showWindow on my NSWindowController twice on 10.5?

查看:1043
本文介绍了为什么我必须在我的NSWindowController上调用showWindow两次在10.5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSWindowController的子类,我使用它从一个nib加载一个窗口并显示在屏幕上。下面是当我想显示窗口时调用的代码。在10.6调用showCustomWindow时显示窗口,但是在10.5这个方法必须调用两次才能显示窗口。

I've got a subclass of an NSWindowController that I'm using to load a window from a nib and show it on the screen. Below is the code that is called when I want to show the window. On 10.6 when showCustomWindow is called the window is displayed, but on 10.5 this method has to be called twice to get the window to display.

-(IBAction)showCustomWindow:(id)sender 
{
   if(!windowController){
       windowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindow"];
    }

    [windowController showWindow:self];
}

此窗口有可见启动时选中,取消选中它似乎。

The window has "Visible at Launch" checked and unchecking it didn't seem to make a difference.

编辑:我意识到我遇到的问题与我的NSWindowController或showWindow无关。我有正确设置。我没有发现,并不是所有的类都实现awakeFromNib。在我的一个NSView子类(这是在nib中,我试图加载),我调用[super awakeFromNib],这给了我一个不响应选择器(但只有10.5,这是奇怪的)。所以,我可以刚刚出去[超清晰FromNib],但我选择了希望更健壮:

I realized that the problem I was having was not related to my NSWindowController or showWindow. I had that set up correctly. I did however find out that not all classes implement awakeFromNib. In one of my NSView subclasses (that was in the nib I was trying to load), i was calling [super awakeFromNib] which was giving me a "does not respond to selector" (but only on 10.5 which is strange). So, I could have just taken out [super awakeFromNib] but I opted for the hopefully more robust:

if([NSView instancesRespondToSelector:@selector(awakeFromNib)]) {
    [super awakeFromNib];
}

这允许我的nib正常加载和showWindow正常工作。

That allowed my nib to load normally and showWindow to work properly.

推荐答案

如果您想使用 -showWindow:控制该窗口可见性的时间。

Visible at Launch should be unchecked if you want to use -showWindow: to control the timing of that window's visibility.

其他所有内容从您显示的内容开始,所以这只是一个猜测,忘记将文件所有者对象上的窗口插座连接到nib中的窗口?

Everything else seems right from what you've shown us so this is just a guess but did you forget to connect the window outlet on your File's Owner object to the window in your nib?

这篇关于为什么我必须在我的NSWindowController上调用showWindow两次在10.5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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