Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.4 and later. |
Companion guide | |
Declared in | NSTreeController.h |
Related sample code |
The NSTreeController is a bindings compatible controller that manages a tree of objects. It provides selection and sort management. Its primary purpose is to act as the controller when binding NSOutlineView and NSBrowser instances to a hierarchial collection of objects.
An NSTreeController requires that you describe how the tree of objects is traversed by specifying the key path for child objects. All child objects for the tree must be key-value-coding compliant for the same child key path. If necessary you should implement accessor methods in your model classes, or categories on those classes, that map the child key to the appropriate class-specific method name.
An optional count key path can be specified that, if provided, returns the number of child objects available. Your model objects are expected to update the value of the count key path in a key-value-observing compliant method. You can optionally provide a leaf key path that specifies a key in your model object that returns YES
if the object is a leaf node, and NO
if it is not. Providing this key path prevents the NSTreeController from having to determine if a child object is a leaf node by examining the child object and as a result improve performance.
The root content object can be a single object, or an array of objects.
– setSelectionIndexPath:
– selectionIndexPath
– setSelectionIndexPaths:
– selectionIndexPaths
– selectedObjects
– selectedNodes
– setSelectsInsertedObjects:
– selectsInsertedObjects
– addSelectionIndexPaths:
– removeSelectionIndexPaths:
– setAvoidsEmptySelection:
– avoidsEmptySelection
– setPreservesSelection:
– preservesSelection
– setAlwaysUsesMultipleValuesMarker:
– alwaysUsesMultipleValuesMarker
– add:
– addChild:
– canAddChild
– canInsert
– canInsertChild
– insert:
– insertChild:
– insertObject:atArrangedObjectIndexPath:
– insertObjects:atArrangedObjectIndexPaths:
– remove:
– removeObjectAtArrangedObjectIndexPath:
– removeObjectsAtArrangedObjectIndexPaths:
– moveNode:toIndexPath:
– moveNodes:toIndexPath:
– setChildrenKeyPath:
– childrenKeyPath
– setCountKeyPath:
– childrenKeyPathForNode:
– countKeyPath
– countKeyPathForNode:
– setLeafKeyPath:
– leafKeyPath
– leafKeyPathForNode:
Adds an object to the receiver after the current selection.
- (void)add:(id)sender
The sender is typically the object that invoked this method.
If the receiver is in object mode newObject
is called and the returned object is added to the collection. If the receiver is in entity mode a new object is created that is appropriate as specified by the entity, and newObject
is not used.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSTreeController.h
Adds a child object to the currently selected item.
- (void)addChild:(id)sender
The sender is typically the object that invoked this method.
If the receiver is in object mode newObject
is called and the returned object is added as a child. If the receiver is in entity mode a new object is created that is appropriate for the relationship as specified by the entity, and newObject
is not used.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSTreeController.h
Adds the objects at the specified indexPaths in the receiver’s content to the current selection.
- (BOOL)addSelectionIndexPaths:(NSArray *)indexPaths
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSTreeController.h
Returns whether the receiver always returns the multiple values marker when multiple objects are selected, even if the selected items have the same value.
- (BOOL)alwaysUsesMultipleValuesMarker
The default is NO
.
This property is observable using key-value observing.
NSTreeController.h
Returns a proxy root tree node containing the receiver’s sorted content objects.
- (id)arrangedObjects
This property is observable using key-value observing.
Prior to Mac OS X v10.5 this method returned an opaque root node representing all the currently displayed objects. This method should be used for binding, no assumption should be made about what methods this object supports.
NSTreeController.h
Returns whether the receiver requires that the content array attempt to maintain a selection at all times.
- (BOOL)avoidsEmptySelection
The default is YES
.
This property is observable using key-value observing.
NSTreeController.h
Returns YES
if a child object can be added to the receiver’s content.
- (BOOL)canAddChild
This property is observable using key-value observing.
NSTreeController.h
Returns YES
if an object can be inserted into the receiver’s content.
- (BOOL)canInsert
This property is observable using key-value observing.
NSTreeController.h
Returns YES
if a child object can be inserted into the receiver’s content.
- (BOOL)canInsertChild
This property is observable using key-value observing.
NSTreeController.h
Returns the key path used to find the children in the receiver’s objects.
- (NSString *)childrenKeyPath
NSTreeController.h
Returns the key path used to find the children in the specified tree node.
- (NSString *)childrenKeyPathForNode:(NSTreeNode *)node
A tree node in the receiver.
A string containing the key path in node that provides the child nodes.
NSTreeController.h
Returns the receiver’s content object.
- (id)content
This property is observable using key-value observing.
NSTreeController.h
Returns the key path used to find the number of children for a node.
- (NSString *)countKeyPath
NSTreeController.h
Returns the key path that provides the number of children for a specified node.
- (NSString *)countKeyPathForNode:(NSTreeNode *)node
A tree node in the receiver.
A string containing the key path in node that provides the number of children.
NSTreeController.h
Creates a new object of the class specified by objectClass
and inserts it into the receiver’s content.
- (void)insert:(id)sender
The sender is typically the object that invoked this method.
If the receiver is in object mode newObject
is called and the returned object is inserted into the collection. If the receiver is in entity mode a new object is created that is appropriate as specified by the entity, and newObject
is not used.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSTreeController.h
Creates a new object of the class specified by objectClass
and inserts it into the receiver’s content as a child of the current selection.
- (void)insertChild:(id)sender
The sender is typically the object that invoked this method.
If the receiver is in object mode newObject
is called and the returned object is inserted as a child. If the receiver is in entity mode a new object is created that is appropriate for the relationship as specified by the entity, and newObject
is not used.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSTreeController.h
Inserts object into the receiver’s arranged objects array at the location specified by indexPath, and adds it to the receiver’s content.
- (void)insertObject:(id)object atArrangedObjectIndexPath:(NSIndexPath *)indexPath
NSTreeController.h
Inserts objects into the receiver’s arranged objects array at the locations specified in indexPaths, and adds them to the receiver’s content.
- (void)insertObjects:(NSArray *)objects atArrangedObjectIndexPaths:(NSArray *)indexPaths
NSTreeController.h
Returns the key path used by the receiver to determine if a node is a leaf key.
- (NSString *)leafKeyPath
NSTreeController.h
Returns the key path that specifies whether the node is a leaf node.
- (NSString *)leafKeyPathForNode:(NSTreeNode *)node
A tree node in the receiver.
A string containing the key path in node that specifies that the node is a leaf node.
NSTreeController.h
Moves the specified tree node to the new index path.
- (void)moveNode:(NSTreeNode *)node toIndexPath:(NSIndexPath *)indexPath
A tree node.
An index path specifying the new position in the receiver’s content.
NSTreeController.h
Moves the specified tree nodes to the new index path.
- (void)moveNodes:(NSArray *)nodes toIndexPath:(NSIndexPath *)startingIndexPath
An array of tree nodes.
An index path specifying the starting position to move the tree nodes to in the receiver’s content.
NSTreeController.h
Returns whether the receiver will attempt to preserve the current selection when the content changes.
- (BOOL)preservesSelection
The default is YES
.
This property is observable using key-value observing.
NSTreeController.h
Use this method to trigger reordering of the receiver’s content.
- (void)rearrangeObjects
Subclasses should invoke this method if any parameter that affects the arranged objects changes.
NSTreeController.h
Removes the receiver’s selected objects from the content.
- (void)remove:(id)sender
The sender is typically the object that invoked this method.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSTreeController.h
Removes the object at the specified indexPath in the receiver’s arranged objects from the receiver’s content.
- (void)removeObjectAtArrangedObjectIndexPath:(NSIndexPath *)indexPath
NSTreeController.h
Removes the objects at the specified indexPaths in the receiver’s arranged objects from the receiver’s content.
- (void)removeObjectsAtArrangedObjectIndexPaths:(NSArray *)indexPaths
NSTreeController.h
Removes the objects at the specified indexPaths from the receiver’s current selection, returning YES
if the selection was changed.
- (BOOL)removeSelectionIndexPaths:(NSArray *)indexPaths
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSTreeController.h
Returns an array of the receiver’s selected tree nodes.
- (NSArray *)selectedNodes
An array containing the receiver’s selected tree nodes
NSTreeController.h
Returns an array containing the receiver’s selected objects.
- (NSArray *)selectedObjects
This property is observable using key-value observing.
NSTreeController.h
Returns the index path of the first object in the receiver’s selection, or nil
if there is no selection.
- (NSIndexPath *)selectionIndexPath
This property is observable using key-value observing.
NSTreeController.h
Returns an array containing the index paths of the receiver’s currently selected objects in the content.
- (NSArray *)selectionIndexPaths
This property is observable using key-value observing.
NSTreeController.h
Returns whether the receiver selects inserted objects automatically.
- (BOOL)selectsInsertedObjects
The default is YES
.
This property is observable using key-value observing.
NSTreeController.h
Sets whether the receiver always returns the multiple values marker when multiple objects are selected, even if they have the same value.
- (void)setAlwaysUsesMultipleValuesMarker:(BOOL)flag
Setting flag to YES
can increase performance if your application doesn’t allow editing multiple values. The default is NO
.
NSTreeController.h
Sets whether the receiver will attempt to avoid an empty selection.
- (void)setAvoidsEmptySelection:(BOOL)flag
If flag is YES
then the receiver will maintain a selection unless there are no objects in the content. The default is YES
.
NSTreeController.h
Sets the key path used by the receiver to access child objects to key.
- (void)setChildrenKeyPath:(NSString *)key
NSTreeController.h
Sets the receiver’s content to content.
- (void)setContent:(id)content
The content can be an array of objects, or a single root object.
NSTreeController.h
Sets the key path used by the receiver to determine the number of objects at a node to key.
- (void)setCountKeyPath:(NSString *)key
Specifying this key path, if the data is available in the model object, can increase performance, but disables insert and remove functionality.
NSTreeController.h
Sets the key path used by the receiver to determine if an object is a leaf node to key.
- (void)setLeafKeyPath:(NSString *)key
Specifying this key path is optional. If the receiver is able to determine that a node is a leaf node, it can disable inserting or adding children to those nodes.
NSTreeController.h
Sets whether the receiver will attempt to preserve selection when the content changes.
- (void)setPreservesSelection:(BOOL)flag
If flag is YES
then the selection will be preserved, if possible. The default is YES
.
NSTreeController.h
Sets the receiver’s current selection to indexPath, returning YES
if the selection was changed.
- (BOOL)setSelectionIndexPath:(NSIndexPath *)indexPath
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSTreeController.h
Sets the receiver’s current selection to indexPaths, returning YES
if the selection was changed.
- (BOOL)setSelectionIndexPaths:(NSArray *)indexPaths
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSTreeController.h
Sets whether the receiver will automatically select objects as they are inserted.
- (void)setSelectsInsertedObjects:(BOOL)flag
If flag is YES
then items will be selected upon insertion. The default is YES
.
NSTreeController.h
Sets the sort descriptors used to arrange the receiver's contents.
- (void)setSortDescriptors:(NSArray *)sortDescriptors
The sortDescriptors parameter contains an array of NSSortDescriptor
objects. Setting sortDescriptors to nil
causes the contents to be arranged in their natural order.
NSTreeController.h
Returns an array containing the sort descriptors used to arrange the receiver's content.
- (NSArray *)sortDescriptors
Returns nil
if the receiver has no sort descriptors configured. This property is observable using key-value observing.
NSTreeController.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-04-10)