Next Page > Hide TOC

NSTreeNode Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in Mac OS X v10.5 and later.
Companion guide
Declared in
NSTreeNode.h

Overview

NSTreeNode simplifies the creation and management of trees of objects. Each tree node represents a model object. A tree node with nil as its parent node is considered the root of the tree.

Tasks

Creating Tree Nodes

Getting Information About a Node

Sorting the Subtree

Class Methods

treeNodeWithRepresentedObject:

Creates and returns a tree node that represents the specified object.

+ (id)treeNodeWithRepresentedObject:(id)modelObject

Parameters
modelObject

The object the tree node represents.

Return Value

An initialized tree node that represents modelObject.

Availability
Declared In
NSTreeNode.h

Instance Methods

childNodes

Returns an array containing receiver’s child nodes.

- (NSArray *)childNodes

Return Value

An array containing the receiver’s child nodes.

Availability
Declared In
NSTreeNode.h

descendantNodeAtIndexPath:

Returns the receiver’s descendent at the specified index path.

- (NSTreeNode *)descendantNodeAtIndexPath:(NSIndexPath *)indexPath

Parameters
indexPath

An index path specifying a descendent of the receiver.

Return Value

A tree node, or nil if the node does not exist.

Availability
Declared In
NSTreeNode.h

indexPath

Returns the position of the receiver relative to its root parent.

- (NSIndexPath *)indexPath

Return Value

An index path that represents the receiver’s position relative to the tree’s root node.

Availability
Declared In
NSTreeNode.h

initWithRepresentedObject:

Initializes a newly allocated tree node that represents the specified object.

- (id)initWithRepresentedObject:(id)modelObject

Parameters
modelObject

The object the tree node represents.

Return Value

An initialized tree node that represents modelObject.

Availability
Declared In
NSTreeNode.h

isLeaf

Returns whether the receiver is a leaf node.

- (BOOL)isLeaf

Return Value

YES if the receiver is a leaf node (has no child nodes), otherwise NO.

Availability
Declared In
NSTreeNode.h

mutableChildNodes

Returns a mutable array that provides read-write access to the receiver’s child nodes.

- (NSMutableArray *)mutableChildNodes

Return Value

A mutable array that provides read-write access to the receiver’s child nodes.

Discussion

Nodes that are inserted into this array have their parent nodes set to the receiver. Nodes that are removed from this array automatically have their parent node set to nil. The array that is returned is observable using key-value observing.

Availability
Declared In
NSTreeNode.h

parentNode

Returns the receiver’s parent node.

- (NSTreeNode *)parentNode

Return Value

The receiver’s parent node.

Availability
Declared In
NSTreeNode.h

representedObject

Returns the object the tree node represents.

- (id)representedObject

Return Value

The object the tree node represents.

Availability
Declared In
NSTreeNode.h

sortWithSortDescriptors:recursively:

Sorts the receiver’s subtree using the values of the represented objects with the specified sort descriptors.

- (void)sortWithSortDescriptors:(NSArray *)sortDescriptors recursively:(BOOL)recursively

Parameters
sortDescriptors

Array of sort descriptors specifying how to sort the represented objects.

recursively

A Boolean that specifies whether the child nodes should be sorted recursively.

Discussion

All the represented objects in the child nodes must be key-value coding compliant for the keys specified in the sort descriptors.

Availability
Declared In
NSTreeNode.h

Next Page > Hide TOC


© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-13)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.