如何在 Cocoa 多窗口应用程序中使窗口成为活动窗口?

发布于 2024-12-09 05:41:07 字数 772 浏览 4 评论 0原文

我有一个多窗口 Cocoa 应用程序,使用之前 问题

一切正常,但是在初始窗口出现后打开的窗口并显示在前面,但它们的状态不是活动的(一切都是灰色的)。我必须明确地单击其框架内部才能使它们成为活动窗口。

到目前为止我的检查:

  • 我已经尝试过 makeKeyAndOrderFront: 但这没有任何区别。
  • NIB中的文件所有者被设置为窗口相应的控制器类。
  • 我可以在调试器中看到每个控制器的实例实际上是相应窗口的所有者。
  • NSThread建议的解决方案不会使window键成为窗口。
  • 尽管窗口是 NSWindow 的实例,但方法 canBecomeKeyWindow 返回 NO
  • 该窗口有一个标题栏并且可以调整大小。

我需要做什么才能显示处于活动状态的后续窗口?

编辑:

我用 SecondaryWindow 子类化 NSWindow 并覆盖 canBecomeKeyWindow 以返回 YES。我更改为 XIB 以使用新创建的 NSWindow 子类。使用调试器单步调试代码,但该窗口仍然没有成为关键窗口。

I have a multi window Cocoa app, implemented using the techniques described in an answer to a previous question.

All works fine, however windows opened after the initial window come up and are shown front, but their state is not active (everything greyed). I have to explicitly click inside their frame to make them the active window.

My checks so far:

  • I've tried makeKeyAndOrderFront: but that doesn't make any difference.
  • The file owner in the NIB is set to the corresponding controller class of the window.
  • I can see in the Debugger that the instance of each controller is actually the owner of the corresponding window.
  • The solution suggested by NSThread does not make the the window key window.
  • The method canBecomeKeyWindow returns NO although the window is an instance of NSWindow.
  • The window has a title bar and is resizable.

What do I need to do to show subsequent windows in an active state?

EDIT:

I subclassed NSWindow with SecondaryWindow and override canBecomeKeyWindow to return YES. I changed to XIB to use the newly created subclass of NSWindow. Stepped through the code with the debugger, but still the window does not become the key window.

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

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

发布评论

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

评论(1

ら栖息 2024-12-16 05:41:07

试试这个

[previousWindow orderBack];
[previousWindow resignKeyWindow];
[newWindow orderFront];
[newWindow makeKeyWindow];
  • 如果窗口有标题栏或调整大小栏,则它可以成为关键窗口。

如果您的应用程序窗口没有标题栏或调整窗口大小
它不能成为关键窗口。

Try this

[previousWindow orderBack];
[previousWindow resignKeyWindow];
[newWindow orderFront];
[newWindow makeKeyWindow];
  • An window can become key window if it have title bar or a resize bar.

If your application window don't have title bar or resize window then
it can't become key window.

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