Search code examples
cocoansmenuitemnsmenu

Cannot seem to setEnabled:NO on 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.

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.

What am I missing?


Solution

  • I solved it with the help of a colleague, so I post it here for others that experience the same issue.

    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];
    }