NSMenuItem Header Binding Enable / Disable Validation

I have a menu in which some menu items use bindings to get their name. These elements are always enabled and cannot automatically enable / disable, since they must NOR call the call for validateUserInterfaceItem :. If you remove the binding by the header, then this will start working again. Menu items have a target set of zero (first responder). If you click on one, it will execute a selector (action).

Bug? What to do?

+6
cocoa cocoa-bindings
source share
1 answer

For some reason, when you set the title of a menu item with bindings, the menu item becomes enabled even if the target / action is nil .

If you want to permanently disable the menu item, you can get around this by associating the enabled menu item with the constant NO :

 NSNumber *alwaysNo = [NSNumber numberWithBool:NO]; [menuItem bind:@"enabled" toObject:alwaysNo withKeyPath:@"boolValue" options:nil]; 

Please note that this is not the most elegant workaround, but in my case it was even cleaner than not using bindings for the header.

+5
source share

All Articles