15
我以编程方式创建NSMenuItem并将其禁用。如果我重写validateMenuItem:方法并为所有项返回YES,菜单项正常工作。已禁用nsmenuitem
为什么当我将菜单告诉autoEnableItems并且不覆盖validateMenuItem方法时,它不会被启用?
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];
感谢您发布您的答案。这帮助了我! – livingtech 2011-11-18 19:22:06
这只是为我节省了很多时间......谢谢。 – 2014-10-18 22:15:02
我忘了通过'setTarget'设置目标。没有正确设置。谢谢! – 2017-02-17 11:34:12