为什么在 10.5 上我必须在 NSWindowController 上调用 showWindow 两次?

发布于 2024-08-07 03:02:07 字数 819 浏览 3 评论 0原文

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

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

    [windowController showWindow:self];
}

该窗口已选中“启动时可见”,取消选中它似乎没有什么区别。

编辑:我意识到我遇到的问题与我的 NSWindowController 或 showWindow 无关。我已经正确设置了。然而我确实发现并非所有类都实现 awakeFromNib。在我的一个 NSView 子类中(在我试图加载的笔尖中),我调用 [super awakeFromNib] ,它给了我一个“不响应选择器”(但仅在 10.5 上,这很奇怪)。所以,我本可以直接取出 [super awakeFromNib],但我选择了希望更强大的:

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

这使得我的笔尖能够正常加载,并且 showWindow 能够正常工作。

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.

Edit: 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];
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

懷念過去 2024-08-14 03:02:08

如果您想使用 -showWindow: 来控制该窗口可见的时间,则应取消选中“启动时可见”。

从您向我们展示的内容来看,其他所有内容似乎都是正确的,因此这只是一个猜测,但是您是否忘记将文件所有者对象上的 window 插座连接到您的窗口中的窗口笔尖?

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

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?

往事随风而去 2024-08-14 03:02:08

您是否在窗口完成从笔尖加载之前调用 -showWindow ?您可能需要在 [MyWindowController awakeFromNib] 中设置一个断点来找出答案。

Are you calling -showWindow before the window has finished loading from its nib? You might want set a breakpoint in [MyWindowController awakeFromNib] to find out.

慵挽 2024-08-14 03:02:08

编辑:好的抱歉我误解了你的问题,发现你需要调用 showWindow 两次。我对此没有答案。

您看到的行为是正确的,因为方法 initWithWindowNibName: 实际上不会加载笔尖。笔尖加载是延迟发生的..因此在调用 showWindow 方法或其他需要加载笔尖的方法(例如 window)之后。

Edit: OK Sorry I misunderstood your question and see that you need to call showWindow twice. I don't have an answer for that.

The behaviour you're seeing is correct since the method initWithWindowNibName: won't actually load the nib. Nib loading happens lazily .. so after you invoke the showWindow method, or some other method such as window that requires the nib to load.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文