views:

21

answers:

2

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.

A: 

Got it working. Created a NSPopuButton with contents from an array and then used that here.

[menu setSubmenu:[(NSPopupButton *array) menu] forItem:menuItem];
1. That isn't valid syntax. 2. Why did you name your pop-up button “array”? And why are you casting it? 3. You probably shouldn't put the same menu in two different places. Make a copy of the pop-up button's menu and use that as the submenu. Or, if you're not actually using the pop-up button, why are you creating one?
Peter Hosey
A: 

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];
papagno