似乎无法在NSMenuItem上设置setEnabled:NO [英] Cannot seem to setEnabled:NO on NSMenuItem
问题描述
我继承了NSMenu
的子类,并通过Interface Builder连接了一堆NSMenuItem
.我已经通过调试器进行了测试,以查看它们是否已真正初始化.
I have subclassed NSMenu
and connected a bunch of NSMenuItem
's via Interface Builder. I have tested via the debugger to see that they really get initialized.
菜单设置为不自动启用项目.仍然,当我将任何我的NSMenuItem设置为[myMenuItem setEnabled:NO]
时,它们仍被启用.即使我从NSMenu子类中调用[self update]
.
The menu is set to not auto enable items. Still when I set any of my NSMenuItem's to [myMenuItem setEnabled:NO]
they continue to be enabled. Even if I call [self update]
from within the NSMenu subclass.
我想念什么?
推荐答案
我在同事的帮助下解决了这个问题,因此我在这里将其发布给遇到相同问题的其他人.
I solved it with the help of a colleague, so I post it here for others that experience the same issue.
您应将NSMenu-sublass设置为自动启用项(默认行为),然后在NSMenu-sublass中实现此方法.
You should set your NSMenu-sublass to auto-enable items (default behaviour) and then implement this method in the NSMenu-sublass.
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
return [menuItem isEnabled];
}
这篇关于似乎无法在NSMenuItem上设置setEnabled:NO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!