Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding NSSubmenu item in NSMenuItem

I want to add a drop down menu in one of the entries in the NSMenu Item. (eg. If you click on the Battery indicator on Finder bar, it has an option for Show->Icon,Time,Percentage). Now I add a MenuItem using the following code:

         menuItem = [menu addItemWithTitle:@"Start"
        action:@selector(start:) keyEquivalent:@""]; 
        [menuItem setTarget:self];

How do I add a submenu Item with this drop down list ? Thanks.

like image 816
ZionKing Avatar asked Aug 18 '10 07:08

ZionKing


1 Answers

This is how I add a submenu to an NSMenu item:

NSMenuItem *mainItem = [[NSMenuItem alloc] init];
[mainItem setTitle:@"Main item"];

NSMenu *submenu = [[NSMenu alloc] init];
[submenu addItemWithTitle:@"Sub item" action:nil keyEquivalent:@""];

[mainItem setSubmenu:submenu];
like image 171
Francesco Papagno Avatar answered Nov 10 '22 22:11

Francesco Papagno