osx NSMenuItem Enabling menu items


Manually enabling menu items

To manually control the enabled state of a menu items the menu that contains it must disable automatic enabling of its items

Menus can turn off automatic enabling in one of two ways:

  1. In the Interface Builder

Interface Builder assistant editor screenshot showing Auto Enables Items disabled

  1. In code

menu.autoenablesItems = false

Both of the mechanisms set the autoenablesItems property on NSMenu.

Once the menu is menu is no longer enabling and disabling menu items the menu items can be programmatically set in one of two ways

  1. In Interface Builder
  2. In code
menuItem.enabled = true

Automatically enabling menu items

Menu items can be automatically enabled by connecting menu items actions to the first responder and implementing the delivered action on an object in the responder chain as described by Apple's docs.