문제

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