菜单项已启用,但仍呈灰色
我有一个菜单,其中包含在界面生成器中创建的多个项目。看起来不错,并且选中了“启用”。但是当我运行该应用程序时,所有菜单项都呈灰色。
我检查了 isEnabled
,它返回 true。
此外,以编程方式创建的菜单项(使用 initWithTitle
且不使用界面生成器)也可以正常工作。
我在这里错过了什么吗?我对 OS X 开发确实很陌生。
I have a menu with several items created in interface builder. It looks fine there and 'enabled' is checked. But when I run the application, all menu items are grayed out.
I've checked isEnabled
, it returns true.
Also, menu items created programmatically (with initWithTitle
and without interface builder) work just fine.
Am I missing something here? I'm really quite new to OS X development.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请记住设置菜单项的目标并确保所述目标实现菜单项的操作方法。
https://developer.apple.com/library /mac/documentation/Cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.html
Remember to set your menu item's target and ensure that said target implements the menu item's action method.
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.html
如果有人可能会通过谷歌搜索并受益,则声明“Action”方法时没有
:(id)sender
参数:奇怪的是,
NSMenuItem
setAction 方法> 吃了它并没有抱怨。那好吧。In case somebody might google this out and benefit, 'Action' method was declared without
:(id)sender
parameter:Strangely,
setAction
method inNSMenuItem
ate it and didn't complain. Oh well.啊,使用 NSMenu 的麻烦...
查看
。通常实现会很简单:
Ah, the plague of using
NSMenu
...Check out
<NSMenuValidation>
.Usually the implementation will be as simple as: