バインディングとコアデータで構成された NSPopUpButton があります。すべてが完全に機能していますが、「リストを編集する」アクションを実装するアイテムを追加したいと思います。
Item 1
Item 2
Item 3
Item 4
------
Edit List..
これはバインディングで可能ですか?
答えはノーだと思います。少なくとも完全ではありません。プログラムでボタンにコンテンツを提供し、 Selected Valueのバインディングを維持すると思ったので、これが私が思いついたものです
- (void)updateSectorPopupItems
{
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Sector"];
NSSortDescriptor *sortPosition = [[NSSortDescriptor alloc] initWithKey:@"position" ascending:YES];
[request setSortDescriptors:@[sortPosition]];
NSError *anyError = nil;
NSArray *fetchObjects = [_gdcManagedObjectContext executeFetchRequest:request
error:&anyError];
if (fetchObjects == nil) {
DLog(@"Error:%@", [anyError localizedDescription]);
}
NSMutableArray *sectorNames = [NSMutableArray array];
for (NSManagedObject *sector in fetchObjects) {
[sectorNames addObject:[sector valueForKey:@"sectorCatagory"]];
}
[_sectorPopUpBotton addItemsWithTitles:sectorNames];
NSInteger items = [[_sectorPopUpBotton menu] numberOfItems];
if (![[_sectorPopUpBotton menu] itemWithTag:1] ) {
NSMenuItem *editList = [[NSMenuItem alloc] initWithTitle:@"Edit List..." action:@selector(showSectorWindow:) keyEquivalent:@""];
[editList setTarget:self];
[editList setTag:1];
[[_sectorPopUpBotton menu] insertItem:editList atIndex:items];
}
私がこれで抱えているいくつかの問題
1) を使用してメニュー項目を追加する場合
[_sectorPopUpBotton menu] insertItem:editList atIndex:items];
atIndex に入力された値に関係なく、項目は常にメニュー リストの一番上に表示されます。
2) 「リストの編集...」メニュー項目でアクションを開始したいのですが、これが値として選択されないようにするにはどうすればよいですか?