代码之家  ›  专栏  ›  技术社区  ›  Tom Dalling

InstableView如何通过绑定修改NSarrayController的选择?

  •  4
  • Tom Dalling  · 技术社区  · 15 年前

    假设我有以下情况:

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

    当我在InstableView中选择不同的行时,它会神奇地更新NSarrayController(PersonController)选择。InstableView是如何做到这一点的?它是这样做的吗?

    - (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,我希望它像i nstableview那样修改绑定nsarraycontroller的选择。

    1 回复  |  直到 13 年前
        1
  •  9
  •   Dov    13 年前

    凭直觉,我骑了过去。 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

    尽管我所做的唯一绑定是到i nstablecolumn对象的“value”,但看起来ib正在自动添加其他绑定。 非稳定视图 可以修改 NSArrayController 选择,因为它是绑定的 selectionIndexes 自动在ib中。

    这在 NSTableView Bindings Reference ,两者兼而有之 选择索引 sortDescriptors .