PATH  Documentation > Mac OS X > Application Kit Reference: Objective-C

Table of Contents

NSOutlineView


Inherits from:
NSTableView : NSView : NSResponder : NSObject
Conforms to:
NSCoding
(NSResponder)
NSObject (NSObject)
Declared in:
AppKit/NSOutlineView.h



Class at a Glance


An NSOutlineView object uses a row-and-column format to display hierarchical data that can be expanded and collapsed, such as directories and files in a file system. A user can expand and collapse rows, edit values, and resize and rearrange columns.

Principal Attributes


Creation



Interface Builder

Commonly Used Methods



- dataSource Returns the object that provides the data to be displayed (method of NSTableView).
- numberOfRows Returns the number of rows in the NSOutlineView (method of NSTableView).
- collapseItem: Causes an item to be collapsed.
- expandItem: Causes an item to be expanded.
- reloadItem:reloadChildren: Informs the NSOutlineView that data for an item has changed and needs to be retrieved and redisplayed.


Class Description



Note: The NSOutlineView class and its supporting informal protocol NSOutlineDataSource are under development and Interface Builder does not yet include support for working with it. If you want to use an NSOutlineView, you can instantiate it programmatically, or, in Interface Builder, you can drag a table view onto your interface and change its class name to NSOutlineView.

Before reading about NSOutlineView, you should read the documentation for its parent class, NSTableView. An NSOutlineView displays data for a set of related items, with rows representing individual items and columns representing the attributes of those items. As with an NSTableView, each item in an outline view represents a set of values for a particular real-world entity, such as an employee or a bank account. In addition, NSOutlineView provides the ability to expand or collapse rows containing hierarchical data.

An item in an NSOutlineView is expandable if it can contain other items. An expandable item is distinguished visually by an expansion symbol. In Cocoa, an expandable item contains an outline triangle, which points to the right when the item is collapsed and points down when the item is expanded. Clicking on the outline triangle causes it to change position. It also causes the item to be expanded or collapsed, depending on the new state of the outline triangle. An item can be expanded even if it contains no items.

Items inside an expanded item are indented. By default, as a user expands or collapses nested items, the width of the column is resized so that it is just wide enough to display the widest item, based on the width of the items and their indentation in the hierarchy. Justification follows the current system justification. To turn off automatic resizing, use setAutoResizesOutlineColumn:. Note that an item may consist of text, an image, or anything else that can be drawn by a subclass of NSCell.

An NSOutlineView is typically displayed in an NSScrollView, as shown below.

[image: Art/OutlineView.gif]

In this illustration, the NSOutlineView consists of just the rows and columns that display values. The header is drawn by two auxiliary views: a header view that draws the column headers and a corner view that draws the blank square above the vertical scroller. These auxiliary views are described in the documentation for NSTableView.


Behavior Inherited from NSTableView


An outline view inherits much of its behavior from its parent class, NSTableView. As a result, many operations supported by a table view, such as selecting rows or columns, repositioning columns by dragging column headers, and so on, are also supported by an outline view. Your application has control of these features, and can configure the view's parameters to allow or disallow certain operations. For example, you might choose not to allow editing or rearranging for specific columns.

The NSTableView class also provides methods for working with data, responding to mouse clicks, setting grid attributes, editing cells, and performing other operations. For full information on these methods, see the documentation for NSTableView.


Data Source Messages


For more information on NSOutlineView's data source methods, see "Methods Implemented By the Delegate" .


Delegate Messages


NSOutlineView adds several delegate messages to those defined by its superclass, NSTableView. In addition, it redefines certain NSTableView delegate methods to be item-based instead of row-based. Together, these methods give the delegate control over the appearance of individual cells in the table, over changes in selection, and over editing of cells.

Delegate methods that request permission to alert the selection or edit a value are invoked during user actions that affect the NSOutlineView, but are not invoked by programmatic changes to the view. When making changes programmatically, you decide whether you want the delegate to intervene and, if so, you send the appropriate message (checking first that the delegate responds to that message). Because the delegate methods involve the actual data displayed by the NSOutlineView, the delegate is typically the same object as the data source, though this is not a requirement.

NSOutlineView redefines these delegate messages based on similar messages in NSTableView:

NSOutlineView defines these additional delegate messages:

In addition to these methods, the delegate is automatically registered to receive messages corresponding to NSOutlineView notifications. These inform the delegate when the selection changes or is about to change, when a column is moved or resized, and when an item is expanded or collapsed:


Delegate Message Notification
outlineViewColumnDidMove: NSOutlineViewColumnDidMoveNotification
outlineViewColumnDidResize: NSOutlineViewColumnDidResizeNotification
outlineViewSelectionDidChange: NSOutlineViewSelectionDidChangeNotification
outlineViewSelectionIsChanging: NSOutlineViewSelectionIsChangingNotification
outlineViewItemDidExpand: NSOutlineViewItemDidExpandNotification
outlineViewItemDidCollapse: NSOutlineViewItemDidCollapseNotification




Method Types


Expanding and collapsing the outline
- isExpandable:
- expandItem:
- expandItem:expandChildren:
- collapseItem:
- collapseItem:collapseChildren:
- isItemExpanded:
Redisplaying information
- reloadItem:
- reloadItem:reloadChildren:
Converting between items and rows
- itemAtRow:
- rowForItem:
Setting the outline column
- setOutlineTableColumn:
- outlineTableColumn
Setting the indentation
- levelForItem:
- levelForRow:
- setIndentationPerLevel:
- indentationPerLevel
- setIndentationMarkerFollowsCell:
- indentationMarkerFollowsCell
Persistence
- autosaveExpandedItems
- setAutosaveExpandedItems:


Instance Methods



autoResizesOutlineColumn

- (BOOL)autoResizesOutlineColumn

Returns whether the receiver automatically resizes its outline column when the user expands or collapses items. The outline column contains the cells with the expansion symbols and is generally the first column. The default is YES (the outline column is automatically resized).

autosaveExpandedItems

- (BOOL)autosaveExpandedItems

Returns whether the expanded items in the receiver are automatically saved.

The outline view information is saved separately for each user and for each application that user uses. Note that if autosaveName returns nil, this setting is ignored and outline information isn't saved.

See Also: - autosaveName (NSTableView), - autosaveTableColumns (NSTableView), - setAutosaveExpandedItems:



collapseItem:

- (void)collapseItem:(id)item

Collapses item if item is expanded and expandable, otherwise does nothing. If collapsing takes place, posts item collapse notification.

See Also: - expandItem:



collapseItem:collapseChildren:

- (void)collapseItem:(id)item collapseChildren:(BOOL)collapseChildren

If collapseChildren is set to NO, collapses item only (identical to collapseItem:). If collapseChildren is set to YES, recursively collapses item and its children. For each item collapsed, posts item collapsed notification.

See Also: - collapseItem:



expandItem:

- (void)expandItem:(id)item

Expands item if item is expandable and is not already expanded; otherwise, does nothing. If expanding takes place, posts item expanded notification.

See Also: - collapseItem:



expandItem:expandChildren:

- (void)expandItem:(id)item expandChildren:(BOOL)expandChildren

If expandChildren is set to NO, expands item only (identical to expandItem:). If expandChildren is set to YES, recursively expands item and its children. For each item expanded, posts item expanded notification.

See Also: - collapseItem:collapseChildren:



indentationMarkerFollowsCell

- (BOOL)indentationMarkerFollowsCell

Returns YES if the expansion symbol in an expanded item is displayed in the cell with the item and NO if the symbol is displayed system-justified in the column. The default is YES.

See Also: - setIndentationMarkerFollowsCell:



indentationPerLevel

- (float)indentationPerLevel

Returns the current indentation per level, in points.

See Also: - setIndentationPerLevel:



isExpandable:

- (BOOL)isExpandable:(id)item

Returns YES if item is expandable-that is, item can contain other items.

See Also: - expandItem:, - isItemExpanded:



isItemExpanded:

- (BOOL)isItemExpanded:(id)item

Returns YES if item is expanded.

See Also: - expandItem:, - isExpandable:



itemAtRow:

- (id)itemAtRow:(int)row

Returns the item associated with row.

See Also: - rowForItem:



levelForItem:

- (int)levelForItem:(id)item

Returns the indentation level for item.

See Also: - indentationPerLevel, - levelForRow:



levelForRow:

- (int)levelForRow:(int)row

Returns the indentation level for row.

See Also: - indentationPerLevel, - levelForItem:



outlineTableColumn

- (NSTableColumn *)outlineTableColumn

Returns the table column in which hierarchical data is displayed.

See Also: - setOutlineTableColumn:



reloadItem:

- (void)reloadItem:(id)item

Reloads and redisplays the data for item.

See Also: - reloadItem:reloadChildren:



reloadItem:reloadChildren:

- (void)reloadItem:(id)item reloadChildren:(BOOL)reloadChildren

If reloadChildren is set to NO, reloads and redisplays the data for item only (identical to reloadItem:). If reloadChildren is set to YES, recursively reloads and redisplays the data for item and its children. It is not necessary, or efficient, to reload children if the item is not expanded.

See Also: - reloadItem:



rowForItem:

- (int)rowForItem:(id)item

Returns the row associated with item.

See Also: - itemAtRow:



setAutoResizesOutlineColumn:

- (void)setAutoResizesOutlineColumn:(BOOL)resize

Sets whether the receiver automatically resizes its outline column when the user expands or collapses an item. The outline column contains the cells with the expansion symbols and is generally the first column. The default is YES (the outline column is automatically resized).

setAutosaveExpandedItems:

- (void)setAutosaveExpandedItems:(BOOL)flag

Sets whether the expanded items in the receiver are automatically saved. If flag is different from the current value, this method also reads in the saved information and sets the outline view's options to match.

The outline information is saved separately for each user and for each application that user uses.

If autosaveName returns nil or if you haven't implemented the data source methods outlineView:itemForPersistentObject: and outlineView:persistentObjectForItem:, this setting is ignored and expanded item information isn't saved.

Note that you can have separate settings for autosaveExpandedItems and autosaveTableColumns, so you could, for example, save expanded item information, but not table column positions.

See Also: - autosaveExpandedItems, - setAutosaveTableColumns: (NSTableView)



setIndentationMarkerFollowsCell:

- (void)setIndentationMarkerFollowsCell:(BOOL)drawInCell

Sets whether the expansion symbol in an item should be displayed in the cell with the item or left-justified in the column. The default is YES (the symbol is displayed in the cell).

See Also: - indentationMarkerFollowsCell



setIndentationPerLevel:

- (void)setIndentationPerLevel:(float)newIndentLevel

Sets indentation per level, in points, to newIndentLevel.

See Also: - indentationPerLevel



setOutlineTableColumn:

- (void)setOutlineTableColumn:(NSTableColumn *)outlineTableColumn

Sets the table column in which hierarchical data is displayed to outlineTableColumn.

See Also: - outlineTableColumn




Methods Implemented By the Delegate

Methods Implemented By the Data Source. Specifying nil as the item will refer to the "root" item.


outlineView:child:ofItem:

- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item

Returns the child item at the specified index. Children of a given parent item are accessed sequentially. If item is nil, this method should return the appropriate child item of the root object.

See Also: - outlineView:numberOfChildrenOfItem:



outlineView:isItemExpandable:

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item

This method should return YES if item can be expanded to display its children.

outlineView:itemForPersistentObject:

- (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object

Returns the item for the archived object. If the item is an archived object, this may return the object. You must implement this method if you are automatically saving expanded items (that is, autosaveExpandedItems returns YES). When the outline view is restoring the saved expanded items, this method is called for each expanded item, to translate the archived object to an outline view item.

outlineView:numberOfChildrenOfItem:

- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item

Returns the number of child items encompassed by item. If item is nil, this method should return the number of children for the top-level item.

outlineView:objectValueForTableColumn:byItem:

- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item

Returns the data object associated with the specified item. The item is located in the specified tableColumn of the view.

outlineView:persistentObjectForItem:

- (id)outlineView:(NSOutlineView *)outlineView persistentObjectForItem:(id)item

Returns an archived object for item. If the item is an archived object, this may return the item. You must implement this method if you are automatically saving expanded items (that is, autosaveExpandedItems returns YES). When the outline view is saving the expanded items, this method is called for each expanded item, to translate the outline view item to an archived object.

outlineView:setObjectValue:forTableColumn:byItem:

- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item

Sets the data object for the specified item. The object parameter contains the data to be set. The item is located in the specified tableColumn of the view.

Outline views support a data-source delegate in addition to the regular delegate object. The data-source delegate provides data and information about that data to the outline view. The regular delegate object handles all other delegate responsibilities for the outline view.



outlineViewColumnDidMove:

- (void)outlineViewColumnDidMove:(NSNotification *)notification

Invoked whenever the user moves a column in the outline view. This method is invoked as a result of posting an NSOutlineViewColumnDidMoveNotification.

See Also: NSOutlineViewColumnDidMoveNotification (notification)



outlineViewColumnDidResize:

- (void)outlineViewColumnDidResize:(NSNotification *)notification

Invoked whenever the user resizes a column in the outline view. This method is invoked as a result of posting an NSOutlineViewColumnDidResizeNotification.

See Also: NSOutlineViewColumnDidResizeNotification (notification)



outlineViewItemDidCollapse:

- (void)outlineViewItemDidCollapse:(NSNotification *)notification

Invoked whenever the user collapses an item in the outline view. This method is invoked as a result of posting an NSOutlineViewItemDidCollapseNotification.

See Also: NSOutlineViewItemDidCollapseNotification (notification)



outlineViewItemDidExpand:

- (void)outlineViewItemDidExpand:(NSNotification *)notification

Invoked whenever the user expands an item in the outline view. This method is invoked as a result of posting an NSOutlineViewItemDidExpandNotification.

See Also: NSOutlineViewItemDidExpandNotification (notification)



outlineViewItemWillCollapse:

- (void)outlineViewItemWillCollapse:(NSNotification *)notification

Invoked whenever the user is about to collapse an item in the outline view. This method is invoked as a result of posting an NSOutlineViewItemWillCollapseNotification

outlineViewItemWillExpand:

- (void)outlineViewItemWillExpand:(NSNotification *)notification

Invoked whenever the user is about to expand an item in the outline view. This method is invoked as a result of posting an NSOutlineViewItemWillExpandNotification

outlineViewSelectionDidChange:

- (void)outlineViewSelectionDidChange:(NSNotification *)notification

Invoked immediately after the outline view's selection has changed. This method is invoked as a result of posting an NSOutlineViewSelectionDidChangeNotification.

See Also: NSOutlineViewSelectionDidChangeNotification (notification)



outlineViewSelectionIsChanging:

- (void)outlineViewSelectionIsChanging:(NSNotification *)notification

Invoked whenever the outline view's selection changes. This method is invoked as a result of posting an NSOutlineViewSelectionIsChangingNotification.

See Also: NSOutlineViewSelectionIsChangingNotification (notification)



outlineView:shouldCollapseItem:

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item

Returns YES to permit outlineView to collapse item, NO to deny permission. The delegate can implement this method to disallow collapsing of specific items.

outlineView:shouldEditTableColumn:item:

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item

Returns YES to permit outlineView to edit the cell specified by tableColumn and item, NO to deny permission. The delegate can implement this method to disallow editing of specific cells.

outlineView:shouldExpandItem:

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item

Returns YES to permit outlineView to expand item, NO to deny permission. The delegate can implement this method to disallow expanding of specific items.

outlineView:shouldSelectItem:

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item

Returns YES to permit outlineView to select item, NO to deny permission. The delegate can implement this method to disallow selection of particular items.

outlineView:shouldSelectTableColumn:

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectTableColumn:(NSTableColumn *)tableColumn

Returns YES to permit outlineView to select tableColumn, NO to deny permission. The delegate can implement this method to disallow selection of specific columns.

outlineView:willDisplayCell:forTableColumn:item:

- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item

Informs the delegate that outlineView is about to display the cell specified by tableColumn and item. The delegate can modify cell to alter its display attributes; for example, making uneditable values display in italic or gray text.

outlineView:willDisplayOutlineCell:forTableColumn:item:

- (BOOL)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item

Informs the delegate that outlineView is about to display cell (the cell used to draw the expansion symbol) for the column and item specified by tableColumn and item. The delegate can modify cell to alter its display attributes.

selectionShouldChangeInOutlineView:

- (BOOL)selectionShouldChangeInOutlineView:(NSOutlineView *)outlineView

Returns YES to permit outlineView to change its selection (typically a row being edited), NO to deny permission. For example, if the user is editing a cell and enters an improper value, the delegate can prevent the user from selecting or editing any other cells until a proper value has been entered into the original cell. The delegate can implement this method for complex validation of edited rows based on the values of any of their cells.


Notifications


NSOutlineViewColumnDidMoveNotification

Posted whenever a column is moved by user action in the NSOutlineView. This notification contains a notification object and a userInfo dictionary. The notification object is the NSOutlineView in which a column moved. The userInfo dictionary contains these keys and values:
Key Value
NSOldColumn The column's original index (an NSNumber)
NSNewColumn The column's present index (an NSNumber)

See Also: moveColumn:toColumn: (NSTableView)

NSOutlineViewColumnDidResizeNotification

Posted whenever a column is resized in the NSOutlineView.This notification contains a notification object and a userInfo dictionary. The notification object is the NSOutlineView in which a column was resized. The userInfo dictionary contains these keys and values:
Key Value
NSOldWidth The column's original width (an NSNumber)

NSOutlineViewItemDidCollapseNotification

Posted whenever an item is collapsed. This notification contains a notification object and a userInfo dictionary. The notification object is the NSOutlineView in which an item was collapsed. The userInfo dictionary contains these keys and values:
Key Value
NSObject The item that was collapsed (an id)

NSOutlineViewItemDidExpandNotification

Posted whenever an item is expanded. This notification contains a notification object and a userInfo dictionary. The notification object is the NSOutlineView in which an item was expanded. The userInfo dictionary contains these keys and values:
Key Value
NSObject The item that was expanded (an id)

NSOutlineViewSelectionDidChangeNotification

Posted after the NSOutlineView's selection changes.This notification contains a notification object but no userInfo dictionary. The notification object is the NSOutlineView whose selection changed.

NSOutlineViewSelectionIsChangingNotification

Posted as the NSOutlineView's selection changes (while the mouse is still down). This notification contains a notification object but no userInfo dictionary. The notification object is the NSOutlineView whose selection is changing.

NSOutlineViewItemWillCollapseNotification

Description forthcoming.

NSOutlineViewItemWillExpandNotification

Description forthcoming.

Table of Contents