1

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?

Swift Dev Journal
  • 19,282
  • 4
  • 56
  • 66
ScottHa
  • 31
  • 10
  • Simply add additional menu items from the library or by copy-pasting... – Macmade Aug 15 '19 at 03:31
  • Or duplicate an item with Command-d. – Willeke Aug 15 '19 at 08:26
  • Thank you. It's easier to do this in code, I found. – ScottHa Aug 15 '19 at 12:00
  • You might have avoided some of the downvotes by further explaining the problem you were having, for example why it was easier to programmatically add the menu item rather than just dragging one from the IB Library. – red_menace Aug 15 '19 at 20:28
  • I literally spent hours trying to find something in the Attribute Inspector that would "add cells" or "add menu items" and allow you to specify the number, then edit the additions. I finally gave up and did it programatically. I did find an unanswered question someplace that asked them same thing so it has appeared to confuse at least one other person as well. Appreciate the help! – ScottHa Aug 16 '19 at 20:06

4 Answers4

1

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.

Copy and paste the menu item to add more

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
1

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];
ScottHa
  • 31
  • 10
1

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
RickJansen
  • 1,615
  • 18
  • 24
0

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) 
dimaskpz
  • 81
  • 8