I want to sort the NSMenuItem
s of a NSPopUButton
alphabetically.
I checked the cocoa reference and i can't find a function that does this.
Am i missing something or i have to write my own sorting function?
Thanks in advance
Asked
Active
Viewed 455 times
0

ozmax
- 470
- 6
- 17
1 Answers
3
There is no method to sort the items in place, you can however:
- Use
itemArray
it get an array of all the items - Sort that array using one of the
NSArray
sort methods - Remove the existing items from the menu
removeAllItems
- Unfortunately there is no multiple add method so use a fast enumeration over your sorted array and
addItem:
each one.

CRD
- 52,522
- 5
- 70
- 86
-
that's what i figured out too. i used arrays like you said and did the job. specifically i gathered the titles in an `NSMutableArray unsortedValues` then `NSArray *sortedValues = [unsortedValues sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];` (with NSPopUpButton = mymenu) `[mymenu addItemsWithTitles:sortedValues];` thank you for your reply btw :) – ozmax Nov 25 '12 at 23:41