) 在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处的项目时执行此操作吗? ......太棒了!
答案 0 :(得分:2)
NSMenuItem *firstItem = [_myPopupButton itemAtIndex:0];
[_myPopupButton removeAllItems];
[[_myPopupButton menu] addItem:firstItem];