Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create NSPopUpButton Programmatically

How can I create an NSPopUpButton programmatically and attach the menu items to it? This is what I have so far but it is not click able nor does it have any menu items attached

help window is just the name of my NSWindow

NSPopUpButton *button = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(10, 0, 50, 50)];
[[helpWindow contentView] addSubview:button];
[button setNeedsDisplay:YES]; 
like image 474
Grant Wilkinson Avatar asked Dec 05 '22 17:12

Grant Wilkinson


2 Answers

You can also create an NSMenuItem then add it to the NSPopUpButton's menu:

NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"menu" action:NULL keyEquivalent:@""];

[[popUpButton menu] addItem:menuItem];
like image 118
pkamb Avatar answered Dec 22 '22 20:12

pkamb


Use the designated initializer initWithFrame:pullsDown:, and then use addItemWithTitle: or addItemsWithTitles: to add the menu items

like image 24
rdelmar Avatar answered Dec 22 '22 18:12

rdelmar