سؤال

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