I programmatically create an NSMenuItem and it is disabled. If I override the validateMenuItem: method and return YES for all items, the menu item works fine.
Why would it not be enabled when I tell the menu to autoEnableItems and dont override the validateMenuItem: method?
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:label action:@selector(methodToLogSomething:) keyEquivalent:@""];
menuItem.representedObject = representedObject;
[menuItem setTarget:self];
[menu insertItem:menuItem atIndex:[[menu itemArray] count]-1];
[menuItem release];
[menu setAutoenablesItems:YES];
It appears that menu items stay disabled if their target and action are not setup properly. In my case, I forgot the :
at the end of my selector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With