Monday, February 15, 2016

NSMenuItem Troubleshooting

Every now and then I run into a problem where a NSMenuItem stays disabled when I think it should be enabled. If you are having a similar problem, here are a few things to check:

  • Make sure the NSMenuItem is hooked up to an action. If a menu item has no action it will never be enabled.
  • Check your validateMenuItem: implementation. Is it setup to reject menu items it doesn't know about?
  • Is the menu item's tag set correctly?
  • Does your application have multiple validateMenuItem: methods? If so, make sure you are debugging the correct method. The method you need to look at is the one implemented by the class whose action the NSMenuItem will trigger. This can be a bit confusing if the target of the action is the First Responder object.

No comments:

Post a Comment