将 NSDocument 设置为 NSMenu 的委托
我有一个菜单项,其状态应取决于打开的 NSDocument
。根据我的理解,要使其状态动态更改,我应该使用 NSMenu
委托方法 menuNeedsUpdate:
。
看来我想让菜单的委托成为 MainMenu.xib
中的第一响应者。但是,Interface Builder 不允许我将其设置为主菜单的委托。如何创建能够访问当前活动文档的代表?
I have a menu item whose state should depend on whichever NSDocument
is open. From my understanding, to make its state change dynamically I should use the NSMenu
delegate method menuNeedsUpdate:
.
It seems like I would want to have the menu's delegate be the First Responder in MainMenu.xib
. However, Interface Builder won't let me set it as the Main Menu's delegate. How can I make a delegate which will be able to access the currently active document?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常在
validateMenuItem:
方法在菜单显示之前被调用。操作的接收者被询问是否启用该项目。但你几乎可以在那里做任何改变。从 10.5 开始,在此类调用期间添加和删除项目也是安全的。I generally make such changes in the
validateMenuItem:
method being called before the menu is shown. The receiver of the action is asked whether the item is to be enabled or not. But you can do pretty much any change there. Since 10.5 it is also safe to add and remove items during such a call.