Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disabled NSMenuItem

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];
like image 996
joels Avatar asked Dec 24 '10 04:12

joels


1 Answers

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.

like image 140
joels Avatar answered Nov 06 '22 04:11

joels