显示 NSWindow

发布于 2024-11-27 23:06:05 字数 257 浏览 0 评论 0原文

单击菜单项会显示一个 NSWindow,但只是第一次,为什么会这样,以及如何修复它?

-(IBAction)menuClick:(id)sender
{   
    if (!formsView) {
        formsView = [[NSWindowController alloc] initWithWindowNibName:@"Forms"];
    }

    [formsView showWindow:self];
}

Clicking menu item shows a NSWindow, but only for first time, why is so that, and how to fix it?

-(IBAction)menuClick:(id)sender
{   
    if (!formsView) {
        formsView = [[NSWindowController alloc] initWithWindowNibName:@"Forms"];
    }

    [formsView showWindow:self];
}

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

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

发布评论

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

评论(3

忆依然 2024-12-04 23:06:05

这与我使用的代码相同并且有效。问题一定出在其他地方。

问题不在于代码,而在于 Interface Builder 中的设置。 (我仍在使用 Xcode 3.2,所以在我的世界中 Interface builder 是一个单独的应用程序。)确保 xib 中的 File's Owner 类设置为 NSWindowController ,并且它的window插座连接到窗口。

如果您不这样做,并且为窗口设置了启动时可见,您将得到您所描述的确切症状。这是因为 initWithWindowNibName 加载 NIB 文件,并且由于 Visible At Launch 标志而显示窗口。但是如果你查看 NSWindowController 实例的 window 属性,你会发现它仍然是 nil。这就是当您再次调用 showWindow 时窗口不会重新显示的原因。 IB 中的连接将窗口与控制器关联起来。

这是一个正确设置了 IB 的项目。

以下是 IB 中的相关设置:

IB的相关设置

That's the same code I use and it works. The problem must be elsewhere.

The problem isn't the code, it's the setup in Interface Builder. (I'm still using Xcode 3.2 so in my world Interface builder is a separate application.) Make sure the class for File's Owner in the xib is set to NSWindowController and that its window outlet is connected to the window.

If you don't do this and Visible At Launch is set for the window, you'll get exactly the symptom you describe. This is because initWithWindowNibName loads the NIB file and the window is shown because of the Visible At Launch flag. But if you look at the window property of your NSWindowController instance you'll see that it is still nil. That's why the window isn't redisplayed when you call showWindow again. It's the connections in IB that associate the window with the controller.

Here's a project that has IB set up correctly.

Here's the relevant settings in IB:

The relevant settings for IB

花想c 2024-12-04 23:06:05
[window makeKeyAndOrderFront:self]
[window makeKeyAndOrderFront:self]
紧拥背影 2024-12-04 23:06:05

您是否在 Interface Builder(未内置于 Xcode 4 中)中取消选中窗口的“关闭时释放”复选框?

Did you uncheck the "release when closed" checkbox in Interface Builder (not built into Xcode 4) for the window?

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