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 に答える