25

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];
pkamb
  • 33,281
  • 23
  • 160
  • 191
joels
  • 7,249
  • 11
  • 53
  • 94

1 Answers1

46

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.

ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193
joels
  • 7,249
  • 11
  • 53
  • 94