NSPopupButton删除除一个以外的所有项目

时间:2014-01-31 20:06:14

标签: nsarray nspopupbutton

) 在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处的项目时执行此操作吗? ......太棒了!

1 个答案:

答案 0 :(得分:2)

NSMenuItem *firstItem  = [_myPopupButton itemAtIndex:0];
[_myPopupButton removeAllItems];
[[_myPopupButton menu] addItem:firstItem];