4

次のような状況があるとします。

代替テキスト

NSTableView で別の行を選択すると、魔法のように NSArrayController (PersonController) の選択が更新されます。NSTableView はこれをどのように行っていますか? それは次のようなことをしますか:

- (void)bind:(NSString *)binding toObject:(id)observableController withKeyPath:(NSString *)keyPath options:(NSDictionary *)options;
{
 if([observableController isKindOfClass:[NSArrayController class]]){
  // got the NSArrayController, which can be used to change selection
 } else {
  // not an NSArrayController, don't try to change selection
 }

 //...
}

私は独自のバインド可能な NSControl を実装しているので、NSTableView のようにバインドされた NSArrayController の選択を変更したいのでお願いします。

4

1 に答える 1

9

直感でbind:toObject:withKeyPath:options:NSTableViewと 両方のNSTableColumnオブジェクトを上書きし、バインディングをログに記録させました。これは出力です:

NSTableColumn["Last Name"].value を NSArrayController のキーパス "arrangedObjects.lastName" にバインド: 0x215fc0
NSTable.content を NSArrayController のキー パス「arrangedObjects」にバインド: 0x215fc0
NSTable.selectionIndexes を NSArrayController のキー パス「selectionIndexes」にバインド: 0x215fc0
NSTable.sortDescriptors を NSArrayController のキー パス「sortDescriptors」にバインド: 0x215fc0
NSTableColumn["First Name"].value を NSArrayController のキー パス "arrangedObjects.firstName" にバインド: 0x215fc0

私が行った唯一のバインディングは NSTableColumn オブジェクトの「値」に対するものでしたが、IB は追加のバインディングを自動的に追加しているようです。IB で自動的にバインドされるためNSTableView、選択を変更できます。NSArrayControllerselectionIndexes

これは、 と の両方について、 NSTableView Bindings Reference で確認されていますselectionIndexessortDescriptors

于 2010-01-19T02:31:43.713 に答える