如何在 Cocoa 多窗口应用程序中使窗口成为活动窗口?
我有一个多窗口 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
returnsNO
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
如果您的应用程序窗口没有标题栏或调整窗口大小
它不能成为关键窗口。
Try this
If your application window don't have title bar or resize window then
it can't become key window.