سؤال

) In a NSPopupButton I have to store different items. These can often change depending on other actions:

  NSArray* array = [NSArray arrayWithArray:mynewobject];
  // Obviously I do not know which items will be found by mynewobject

  //[_myPopupButton removeAllItems]; // ...But I want to mantain itemAtIndex:0!!
  // ..and then:

  for (NSDictionary *dict in array)
  {
      [_myPopupButton addItemWithTitle:[[dict objectForKey:miciomicio] lastPathComponent]]; 
  }

My intention is to delete old items and then add the new ones. Is possible to do this while maintaining item at index 0? ...It would be nice!

هل كانت مفيدة؟

المحلول

NSMenuItem *firstItem  = [_myPopupButton itemAtIndex:0];
[_myPopupButton removeAllItems];
[[_myPopupButton menu] addItem:firstItem];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top