0

) 在 NSPopupButton 我必须存储不同的项目。这些通常会根据其他操作而改变:

  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]]; 
  }

我的意图是删除旧项目,然后添加新项目。在将项目保持在索引 0 的同时可以做到这一点吗?......会很好!

4

1 回答 1

2
NSMenuItem *firstItem  = [_myPopupButton itemAtIndex:0];
[_myPopupButton removeAllItems];
[[_myPopupButton menu] addItem:firstItem];
于 2014-01-31T20:32:47.443 回答