如何在单击 NSStatusItem 时打开一个窗口?
我对可可还很陌生,所以请原谅我犯的任何愚蠢的错误。 我有一个 NSStatusItem,我想用它来打开菜单。然而,据我所知并听说过不同的形式,如果没有自定义视图,您只能使用弹出菜单。这是真的吗?如果是这样,您如何制作自定义视图来执行某些操作(例如,在我的情况下打开一个窗口)?感谢您的任何帮助。
I'm pretty new to cocoa, so please excuse me for any stupid mistakes I make.
I have a NSStatusItem, which I want to use to open up a menu. However as far as I know and have heard across different forms, without a custom view you are restricted to just a pop down menu. Is this true? And if so how do you make a custom view to do something (e.g. open a window in my case)? Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这不是真的。您需要为状态项设置目标和操作,以调用执行您想要的操作的方法(打开窗口)。
您可能还需要调用
[NSApp activateIgnoringOtherApps:nil];
到您的 openWindow: 方法,以确保您打开的窗口不在其他应用程序窗口的后面。No, it is not true. You need to set up the target and action for the status item to call a method which does what you want (opens the window).
You may also want to call
[NSApp activateIgnoringOtherApps:nil];
to your openWindow: method to ensure that the window you open is not behind some other application's window.