如何add/remove NSMenuItem下的子菜单项
How to add/remove a Sub menuItem under the NSMenuItem
如何在运行时动态地add/remove一个Sub MenuItem
下的NSMenuItem
?
我找到了解决方案。
NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
NSMenu *appMenu = [[mainMenu itemAtIndex:5] submenu];
NSMenuItem *item=[[NSMenuItem alloc]initWithTitle:@"Tutorial" action:@selector(actionTutorial:) keyEquivalent:@"T"];
[item setTarget:self];
[item setTag:0];
[appMenu addItem:item];
[appMenu removeItemAtIndex:2]; // which is the index of above added item.
如何在运行时动态地add/remove一个Sub MenuItem
下的NSMenuItem
?
我找到了解决方案。
NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
NSMenu *appMenu = [[mainMenu itemAtIndex:5] submenu];
NSMenuItem *item=[[NSMenuItem alloc]initWithTitle:@"Tutorial" action:@selector(actionTutorial:) keyEquivalent:@"T"];
[item setTarget:self];
[item setTag:0];
[appMenu addItem:item];
[appMenu removeItemAtIndex:2]; // which is the index of above added item.