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 ответ
Решение
NSMenuItem *firstItem = [_myPopupButton itemAtIndex:0];
[_myPopupButton removeAllItems];
[[_myPopupButton menu] addItem:firstItem];