Reputation: 31
In Xcode's Attribute Inspector for an NSPopUpButton there is no way to add any more than the 3 items they have assigned. Is there a way, in Xcode, to add more? How?
Upvotes: 1
Views: 1517
Reputation: 87
this is the NSPopUpButton documentation https://developer.apple.com/documentation/appkit/nspopupbutton
you can add multiple item
@IBOutlet weak var optionPopUpBtn: NSPopUpButton!
let options: [String] = ["item1", "item2", "item3", "item4"]
optionPopUpBtn.addItems(withTitles: options)
Upvotes: 0
Reputation: 1713
Double-click the popup button in IB, the full menu appears, where you can copy/paste items, or duplicate them. They have quite hidden this feature.
Upvotes: 1
Reputation: 31
I have no idea why the question was down voted, I spent several unproductive hours with Xcode to see if I had missed something in the Attributes editor.
The Xcode Attributes Inspector doesn't have the ability to conveniently add more menu items to an NSPopUpButton. The easiest way to add items is to go ahead and create the NSPopUpButton and add it to your interface. Connect the outlets and actions as necessary. Then, in code, use three lines of code to add all your needed menu items. When you run the code, the existing items in the NSPopUpButton need to be removed, an array of items to be added is created next, then the array is added to the button. Here's the code to do that:
theTitleArray = [NSArray arrayWithObjects:@"Item 1", @"Item 2", @"Item 3", @"Item 4", nil];
[theNSPopUpButtonSelectorSelector removeAllItems];
[theNSPopUpButtonSelector addItemsWithTitles:theTitleArray];
Upvotes: 1
Reputation: 89509
The easiest thing you can do is open up the underlying menu for your popupbutton item and simply select an item, copy and paste it to create a new one.
Upvotes: 1