开发者

Cocoa validateUserInterfaceItem and menu item hiding

Using valid开发者_如何学运维ateUserInterfaceItem it is possible to disable/enable a menu item but I need a similar behaviour to hide menu items, have you some hints?


- (BOOL)validateMenuItem:(NSMenuItem *)menuItem

Some details in the docs.

Update:
NSMenus do not hide NSMenuItems if validateMenuItem: returns NO. The according NSMenuItem gets disabled (Which tells the user that the functionality is there, but currently not applicable).
This behavior is also suggested in Apple's HIG. (See the second paragraph in the "Naming Menu Items" section)

Two other notes about NSMenuItem's enabled state:

  • setEnabled only works if autoenablesItems: of the hosting NSMenu is set to YES
  • The default implementation of validateMenuItem: seems to traverse the responder chain to check if the target/action of a NSMenuItem is available.


You could use -(BOOL) validateMenuItem: to remove a menu item when it was unneeded and insert it when required.

See the Menu documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜