Cocoa Key Value Bindings: What are the explanations of the various options for Controller Key?

前端 未结 4 734
醉梦人生
醉梦人生 2021-01-31 22:45

When I bind a control to an NSArrayController using Interface Builder, there are a variety of options under the \"Controller Key\" field in the bindings inspector.

I und

4条回答
  •  花落未央
    2021-01-31 23:10

    These are tricky to find. They seem to be referenced everywhere by various Cocoa books, and even Apple's docs, but I haven't seen anyone unify an explanation of them into a single location. The answer is, Apple defines them inside the docs for each controller class:

    • NSObjectController (doc)
    • NSArrayController (doc)
    • NSDictionaryController (doc)
    • NSTreeController (doc)
    • NSUserDefaultsController (doc)

    These docs are also useful:

    • Cocoa Bindings
    • Cocoa Bindings Reference

    Inheritance for these "Controller" objects looks like so (this is important to discover where some of the "Controller Key" options come from):

    NSController -> NSObjectController
    NSController -> NSObjectController -> NSArrayController
    NSController -> NSObjectController -> NSArrayController -> NSDictionaryController
    NSController -> NSObjectController -> NSTreeController
    NSController -> NSUserDefaultsController
    
    // Note:  NSController is an abstract class (don't worry about it).  It inherits from NSObject.
    

    If you find a Controller Key not defined in the docs for a particular class, it's probably defined in its superclass. Below are all the Controller Keys available for each of the above (Xcode 3.2.1, Interface Builder 3.2.1):

    // **NSObjectController**
    canAdd
    canRemove
    isEditable
    selectedObjects
    selection
    
    
    // **NSArrayController**
    arrangedObjects
    canAdd
    canInsert
    canRemove
    canSelectNext
    canSelectPrevious
    filterPredicate
    isEditable
    selectedObjects
    selection
    selectionIndex
    selectionIndexes
    sortDescriptors
    
    
    // **NSDictionaryController**
    arrangedObjects
    canAdd
    canInsert
    canRemove
    canSelectNext
    canSelectPrevious
    filterPredicate
    isEditable
    selectedObjects
    selection
    selectionIndex
    selectionIndexes
    sortDescriptors
    
    
    // **NSTreeController**
    arrangedObjects
    canAdd
    canAddChild
    canInsert
    canInsertChild
    canRemove
    isEditable
    selectedObjects
    selectedNodes
    selection
    selectionIndexPath
    selectionIndexPaths
    sortDescriptors
    
    
    // **NSUserDefaultsController**
    hasUnappliedChanges
    values
    

    So, find the one on the list you want, look in the docs for that controller class, and you'll find its definition. If it's not there, it's probably defined in the docs for its superclass (likely NSObjectController).

提交回复
热议问题