Вопрос

I want to sort the NSMenuItems 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

Это было полезно?

Решение

There is no method to sort the items in place, you can however:

  1. Use itemArray it get an array of all the items
  2. Sort that array using one of the NSArray sort methods
  3. Remove the existing items from the menu removeAllItems
  4. Unfortunately there is no multiple add method so use a fast enumeration over your sorted array and addItem: each one.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top