开发者

adding NSSubmenu item in NSMenuItem

开发者 https://www.devze.com 2023-01-12 14:23 出处:网络
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).

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:@""开发者_C百科]; 
        [menuItem setTarget:self];

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


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


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

[menu setSubmenu:[(NSPopupButton *array) menu] forItem:menuItem];
0

精彩评论

暂无评论...
验证码 换一张
取 消