NSTableView如何通过绑定修改NSArrayController的选择?

Tom*_*ing 4 cocoa objective-c nstableview nsarraycontroller cocoa-bindings

假设我有以下情况:

alt text http://img693.imageshack.us/img693/5818/controllerselection.png

当我在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
 }

 //...
}
Run Code Online (Sandbox Code Playgroud)

我问,因为我正在实现我自己的可绑定NSControl,我希望它像NSTableView一样修改绑定的NSArrayController的选择.

Tom*_*ing 9

在预感中,我bind:toObject:withKeyPath:options:NSTableView两个NSTableColumn对象进行了覆盖并使它们记录了它们的绑定.这是输出:

Binding NSTableColumn["Last Name"].value to key path "arrangedObjects.lastName" of NSArrayController: 0x215fc0
Binding NSTable.content to key path "arrangedObjects" of NSArrayController: 0x215fc0
Binding NSTable.selectionIndexes to key path "selectionIndexes" of NSArrayController: 0x215fc0
Binding NSTable.sortDescriptors to key path "sortDescriptors" of NSArrayController: 0x215fc0
Binding NSTableColumn["First Name"].value to key path "arrangedObjects.firstName" of NSArrayController: 0x215fc0

尽管我所做的唯一绑定是对NSTableColumn对象的"值",但看起来IB正在自动添加其他绑定.NSTableView能够修改NSArrayController选择,因为它selectionIndexes在IB中自动绑定.

这在NSTableView绑定参考中已经确认,用于selectionIndexessortDescriptors.