I have a list of elements which needs to be displayed in a NSPopUpButton. I want the PopUp button to display the list in alphabetically sorted order. Moreover, there is a NEW MenuItem in the list which would pick up a string from a text field and insert it into the PopUp button. So, there are two questions I would like to ask:
- What is the correct way of displaying a list of elements in sorted order in a NSPopUpButton?
- How should I handle the insertion of new element to NSPopUpButton so that the sorting order is maintained?
I’ve managed to sort the popup button using the following bindings:
Also I have changed the statement in init from:
to
and the sorting is working just fine.
Now the issue is that if I add a Sub-Menu to any of the menu Items and after that I add a new NSMenuItem to the array controller, the Sub-Menu Previously added disappears as shown in images below:
Before adding New Item:

After adding a new Item:

The Same behavior is being displayed when we sort the elements.
Any ideas on fixing this problem??