To open the submenu: performActionForItemAtIndex:
To select and open the menu: selectItemAtIndex: + performClick:
Do not call performActionForItemAtIndex: for an element that does not have a submenu, as you can initiate an action that could have been set by someone else.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSMenu *menu = self.popup.menu; NSMenuItem *item = [menu itemAtIndex:2]; [item setAction:@selector(terminate:)]; [item setTarget:NSApp]; } - (IBAction)action:(id)sender {
Marek h
source share