| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.0 and later.
|
| Declared in | NSOutlineView.h |
| Companion guides |
NSOutlineView is a subclass of NSTableView that 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.
Important:
Like a table view, an outline view does not store its own data, instead it retrieves data values as needed from a data source to which it has a weak reference (see Communicating With Objects). See the NSOutlineViewDataSource informal protocol, which declares the methods that an NSOutlineView object uses to access the contents of its data source object.
An outline view has the following features:
A user can expand and collapse rows.
Each item in the outline view must be unique. In order for the collapsed state to remain consistent between reloads the item's pointer must remain the same.
The view gets data from a data source (see the NSOutlineViewDataSource informal protocol).
The view retrieves only the data that needs to be displayed.
The following are commonly-used methods:
numberOfRows | Returns the number of rows in the receiver. |
collapseItem: | Collapses a given item. |
expandItem: | Expands a given item. |
reloadItem:reloadChildren: | Reloads a given item and, optionally, its children. |
– outlineView:shouldExpandItem: delegate method
– outlineViewItemWillExpand: delegate method
– expandItem:
– expandItem:expandChildren:
– outlineViewItemDidExpand: delegate method
– outlineView:shouldCollapseItem: delegate method
– outlineViewItemWillCollapse: delegate method
– collapseItem:
– collapseItem:collapseChildren:
– outlineViewItemDidCollapse: delegate method
– setOutlineTableColumn:
– outlineTableColumn
– autoresizesOutlineColumn
– setAutoresizesOutlineColumn:
– levelForItem:
– levelForRow:
– setIndentationPerLevel:
– indentationPerLevel
– setIndentationMarkerFollowsCell:
– indentationMarkerFollowsCell
– outlineView:typeSelectStringForTableColumn:item: delegate method
– outlineView:nextTypeSelectMatchFromItem:toItem:forString: delegate method
– outlineView:shouldTypeSelectForEvent:withCurrentSearchString: delegate method
– outlineView:toolTipForCell:rect:tableColumn:item:mouseLocation: delegate method
– outlineView:shouldShowCellExpansionForTableColumn:item: delegate method
– outlineView:shouldSelectTableColumn: delegate method
– outlineView:shouldSelectItem: delegate method
– selectionShouldChangeInOutlineView: delegate method
– outlineViewSelectionIsChanging: delegate method
– outlineViewSelectionDidChange: delegate method
– outlineView:willDisplayCell:forTableColumn:item: delegate method
– outlineView:willDisplayOutlineCell:forTableColumn:item: delegate method
– outlineView:dataCellForTableColumn:item: delegate method
– outlineViewColumnDidMove: delegate method
– outlineViewColumnDidResize: delegate method
– outlineView:shouldEditTableColumn:item: delegate method
– outlineView:mouseDownInHeaderOfTableColumn: delegate method
– outlineView:didClickTableColumn: delegate method
– outlineView:didDragTableColumn: delegate method
– outlineView:heightOfRowByItem: delegate method
– outlineView:shouldTrackCell:forTableColumn:item: delegate method
– outlineView:isGroupItem: delegate method
Returns a Boolean value that indicates whether the receiver automatically resizes its outline column when the user expands or collapses items.
- (BOOL)autoresizesOutlineColumn
YES if the outline column is automatically resized, otherwise NO.
The outline column contains the cells with the expansion symbols and is generally the first column. The default is YES.
NSOutlineView.h
Returns a Boolean value that indicates whether the expanded items in the receiver are automatically saved.
- (BOOL)autosaveExpandedItems
YES if when an item is expanded, the outline view displays the previous expanded state of its contained items, otherwise NO.
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.
Starting in Mac OS X version 10.5, the value for autosaveExpandedItems is saved out in the nib file. The default value is NO.
– autosaveName (NSTableView)– autosaveTableColumns (NSTableView)– setAutosaveExpandedItems:NSOutlineView.h
Collapses a given item.
- (void)collapseItem:(id)item
An item in the receiver.
If item is not expanded or not expandable, does nothing
If collapsing takes place, posts item collapse notification.
NSOutlineView.hCollapses a given item and, optionally, its children.
- (void)collapseItem:(id)item collapseChildren:(BOOL)collapseChildren
An item in the receiver.
Starting in Mac OS X version 10.5, passing 'nil' will collapse each item under the root in the outline view.
If YES, recursively collapses item and its children. If NO, collapses item only (identical to collapseItem:).
For example, this method is invoked with the collapseChildren parameter set to YES when a user Option-clicks the disclosure triangle for an item in the outline view (to collapse the item and all its contained items).
For each item collapsed, posts an item collapsed notification.
NSOutlineView.hReturns the object that provides the data displayed by the receiver.
- (id)dataSource
The object that provides the data displayed by the receiver.
See Writing an Outline View Data Source and the NSOutlineViewDataSource informal protocol specification for more information.
Expands a given item.
- (void)expandItem:(id)item
An item in the receiver.
If item is not expandable or is already expanded, does nothing.
If expanding takes place, posts an item expanded notification.
NSOutlineView.hExpands a specified item and, optionally, its children.
- (void)expandItem:(id)item expandChildren:(BOOL)expandChildren
An item in the receiver.
Starting in Mac OS X version 10.5, passing 'nil' will expand each item under the root in the outline view.
If YES, recursively expands item and its children. If NO, expands item only (identical to expandItem:).
For example, this method is invoked with the expandChildren parameter set to YES when a user Option-clicks the disclosure triangle for an item in the outline view (to expand the item and all its contained items).
For each item expanded, posts an item expanded notification.
NSOutlineView.hReturns the frame of the outline cell for a given row.
- (NSRect)frameOfOutlineCellAtRow:(NSInteger)row
The index of the row for which to return the frame.
The frame of the outline cell for the row at index row, considering the current indentation and the value returned by indentationMarkerFollowsCell. If the row at index row is not an expandable row, returns NSZeroRect.
You can override this method in a subclass to return a custom frame for the outline button cell. If your override returns an empty rect, no outline cell is drawn for that row. You might do that, for example, so that the disclosure triangle will not be shown for a row that should never be expanded.
NSOutlineView.hReturns a Boolean value that indicates whether the indentation marker symbol displayed in the outline column should be indented along with the cell contents, or always displayed left-justified in the column.
- (BOOL)indentationMarkerFollowsCell
YES if the indentation marker is indented along with the cell contents, otherwise NO.
The default is YES.
NSOutlineView.h
Returns the current indentation per level.
- (CGFloat)indentationPerLevel
The current indentation per level, in points.
NSOutlineView.h
Returns a Boolean value that indicates whether a given item is expandable.
- (BOOL)isExpandable:(id)item
An item in the receiver.
YES if item is expandable—that is, item can contain other items, otherwise NO.
NSOutlineView.h
Returns a Boolean value that indicates whether a given item is expanded.
- (BOOL)isItemExpanded:(id)item
An item in the receiver.
YES if item is expanded, otherwise NO.
NSOutlineView.h
Returns the item associated with a given row.
- (id)itemAtRow:(NSInteger)row
The index of a row in the receiver.
The item associated with row.
NSOutlineView.h
Returns the indentation level for a given item.
- (NSInteger)levelForItem:(id)item
An item in the receiver.
The indentation level for item. If item is nil (which is the root item), returns –1.
The levels are zero-based—that is, the first level of displayed items is level 0.
NSOutlineView.h
Returns the indentation level for a given row.
- (NSInteger)levelForRow:(NSInteger)row
The index of a row in the receiver.
The indentation level for row. For an invalid row, returns –1.
The levels are zero-based—that is, the first level of displayed items is level 0.
NSOutlineView.h
Returns the table column in which hierarchical data is displayed.
- (NSTableColumn *)outlineTableColumn
The table column in which hierarchical data is displayed.
Each level of hierarchical data is indented by the amount specified by indentationPerLevel (the default is 16.0), and decorated with the indentation marker (disclosure triangle) on rows that are expandable.
Starting in Mac OS X version 10.5, outline table column data is saved in encodeWithCoder: and restored in initWithCoder:.
NSOutlineView.hReturns the parent for a given item.
- (id)parentForItem:(id)item
The item for which to return the parent.
The parent for item, or nil if the parent is the root.
NSOutlineView.h
Reloads and redisplays the data for item.
- (void)reloadItem:(id)item
NSOutlineView.hReloads a given item and, optionally, its children.
- (void)reloadItem:(id)item reloadChildren:(BOOL)reloadChildren
An item in the receiver.
Starting in Mac OS X version 10.5, passing 'nil' will reload everything under the root in the outline view.
If YES, recursively reloads item and its children. If NO, reloads item only (identical to reloadItem:).
It is not necessary, or efficient, to reload children if the item is not expanded.
NSOutlineView.h
Returns the row associated with a given item.
- (NSInteger)rowForItem:(id)item
An item in the receiver.
The row associated with item, or –1 if item is nil or cannot be found.
NSOutlineView.h
Sets whether the receiver automatically resizes its outline column when the user expands or collapses an item.
- (void)setAutoresizesOutlineColumn:(BOOL)resize
YES if the outline column is automatically resized, otherwise NO.
The outline column contains the cells with the expansion symbols and is generally the first column. The default is YES.
NSOutlineView.hSets whether the expanded items in the receiver are automatically saved.
- (void)setAutosaveExpandedItems:(BOOL)flag
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. YES indicates that when an item is expanded, the outline view displays the previous expanded state of its contained items.
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.
Starting in Mac OS X version 10.5, the value for autosaveExpandedItems is saved out in the nib file. The default value is NO.
– autosaveExpandedItems– setAutosaveTableColumns: (NSTableView)NSOutlineView.hSets the receiver’s data source to a given object.
- (void)setDataSource:(id)anObject
The data source for the receiver. The object must implement the appropriate methods of the NSOutlineViewDataSource informal protocol.
The receiver maintains a weak reference to the data source (see Communicating With Objects). After setting the data source, this method invokes tile.
This method raises an NSInternalInconsistencyException if anObject doesn’t respond to all of outlineView:child:ofItem:, outlineView:isItemExpandable:, outlineView:numberOfChildrenOfItem:, and outlineView:objectValueForTableColumn:byItem:.
Used to “retarget” a proposed drop.
- (void)setDropItem:(id)item dropChildIndex:(NSInteger)index
For example, to specify a drop on an item I, you specify item as 1 and index as NSOutlineViewDropOnItemIndex. To specify a drop between child 2 and 3 of item I, you specify item as I and index as 3 (children are a zero-based index). To specify a drop on an unexpandable item 1, you specify item as I and index as NSOutlineViewDropOnItemIndex.
NSOutlineView.hSets whether the indentation marker symbol displayed in the outline column should be indented along with the cell contents, or always displayed left-justified in the column.
- (void)setIndentationMarkerFollowsCell:(BOOL)drawInCell
The default is YES, the indentation marker is indented along with the cell contents.
NSOutlineView.h
Sets the per-level indentation.
- (void)setIndentationPerLevel:(CGFloat)newIndentLevel
The indentation per level, in points.
NSOutlineView.h
Sets the table column in which hierarchical data is displayed.
- (void)setOutlineTableColumn:(NSTableColumn *)outlineTableColumn
The table column in which hierarchical data is displayed.
Starting in Mac OS X version 10.5, outline table column data is saved in encodeWithCoder: and restored in initWithCoder:.
NSOutlineView.hReturns a Boolean value that indicates whether autoexpanded items should return to their original collapsed state.
- (BOOL)shouldCollapseAutoExpandedItemsForDeposited:(BOOL)deposited
YES if autoexpanded items should return to their original collapsed state, otherwise NO.
Override this method to provide custom behavior. deposited tells whether or not the drop terminated due to a successful drop.
This method is called in a variety of situations. For example, it is sent shortly after outlineView:acceptDrop:item:childIndex: is processed and also if the drag exits the outline view (exiting the view is treated the same as a failed drop).
NSOutlineView.hReturns the cell to use in a given column for a given item.
- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item
The outline view that sent the message.
The table column for which the cell is required. This value may be nil.
The item for which the cell is required.
The cell to use in column tableColumn for item item, or nil (see Discussion). The cell must properly implement copyWithZone: (since it may be copied by by the outline view).
You can return a different data cell for any particular combination of table column and item, or a cell that will be used for the entire row (a full width cell). If tableColumn is non-nil, you should return a cell. Typically you should default to returning the result from [tableColumn dataCellForRow:row].
When each row (identified by the item) is being drawn, this method is first called with a nil value for tableColumn. At this time, you can return a cell that will be used to draw the entire row, acting like a group. If you do return a cell for the 'nil' table column, your implementations of the other corresponding datasource and delegate methods must be prepared to be invoked with a nil value for tableColumn. If do not return a cell for the 'nil' table column, the method will be called once for each column in the outline view, as usual.
NSOutlineView.hSent at the time the mouse button subsequently goes up in outlineView and tableColumn has been “clicked” without having been dragged anywhere.
- (void)outlineView:(NSOutlineView *)outlineView didClickTableColumn:(NSTableColumn *)tableColumn
NSOutlineView.hSent at the time the mouse button goes up in outlineView and tableColumn has been dragged during the time the mouse button was down.
- (void)outlineView:(NSOutlineView *)outlineView didDragTableColumn:(NSTableColumn *)tableColumn
NSOutlineView.hReturns the height in points of the row containing item.
- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
Values returned by this method should not include intercell spacing and must be greater than 0. Implement this method to support an outline view with varying row heights.
For large tables in particular, you should make sure that this method is efficient. NSTableView may cache the values this method returns, so if you would like to change a row's height make sure to invalidate the row height by calling noteHeightOfRowsWithIndexesChanged:. NSTableView automatically invalidates its entire row height cache in reloadData and noteNumberOfRowsChanged.
NSOutlineView.hReturns a Boolean that indicates whether a given row should be drawn in the “group row” style.
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
The outline view that sent the message.
An item in the outline view.
YES to indicate a particular row should have the "group row" style drawn for that row, otherwise NO.
If the cell in that row is an instance of NSTextFieldCell and contains only a string value, the “group row” style attributes are automatically applied for that cell.
NSOutlineView.hSent to the delegate whenever the mouse button is clicked in outlineView while the cursor is in a column header tableColumn.
- (void)outlineView:(NSOutlineView *)outlineView mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn
NSOutlineView.hReturns the first item that matches the searchString from within the range of startItem to endItem
- (id)outlineView:(NSOutlineView *)outlineView nextTypeSelectMatchFromItem:(id)startItem toItem:(id)endItem forString:(NSString *)searchString
The outline view that sent the message.
The first item to search.
The item before which to stop searching. It is possible for endItem to be less than startItem if the search will wrap.
The string for which to search.
The first item—from within the range of startItem to endItem—that matches the searchString, or nil if there is no match.
Implement this method if you want to control how type selection works. You should include startItem as a possible match, but do not include endItem.
It is not necessary to implement this method in order to support type select.
NSOutlineView.hReturns a Boolean value that indicates whether the outline view should collapse a given item.
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item
The outline view that sent the message.
The item that should collapse.
YES to permit outlineView to collapse item, NO to deny permission.
The delegate can implement this method to disallow collapsing of specific items. For example, if the first row of your outline view should not be collapsed, your delegate method could contain this line of code:
return [outlineView rowForItem:item]!=0; |
NSOutlineView.hReturns a Boolean value that indicates whether the outline view should allow editing of a given item in a given table column.
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
YES to permit outlineView to edit the cell specified by tableColumn and item, NO to deny permission.
If this method returns YES, the cell may still not be editable—for example, if you have set up a custom NSTextFieldCell as a data cell, it must return YES for isEditable to allow editing.
The delegate can implement this method to disallow editing of specific cells.
NSOutlineView.hReturns a Boolean value that indicates whether the outline view should expand a given item.
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item
The outline view that sent the message.
The item that should expand.
YES to permit outlineView to expand item, NO to deny permission.
The delegate can implement this method to disallow expanding of specific items.
NSOutlineView.hReturns a Boolean value that indicates whether the outline view should select a given item.
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
YES to permit outlineView to select item, NO to deny permission.
The delegate can implement this method to disallow selection of particular items.
NSOutlineView.hReturns a Boolean value that indicates whether the outline view should select a given table column.
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectTableColumn:(NSTableColumn *)tableColumn
YES to permit outlineView to select tableColumn, NO to deny permission.
The delegate can implement this method to disallow selection of specific columns.
NSOutlineView.hReturns a Boolean value that indicates whether an expansion tooltip should appear in a given column for a given item.
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowCellExpansionForTableColumn:(NSTableColumn *)tableColumn item:(id)item
The outline view that sent the message.
A table column in the outline view.
An item in the outline view.
YES to allow an expansion tooltip to appear in the column tableColumn for item item, otherwise NO.
NSOutlineView.hReturns a Boolean value that indicates whether a given cell should be tracked.
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldTrackCell:(NSCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
The outline view that sent the message.
The cell used to display item item in column tableColumn
A table column in the outline view.
An item in the outline view.
YES if the cell should be tracked for the item item in column tableColumn, otherwise NO.
Normally, only selectable or selected cells can be tracked. If you implement this method, cells which are not selectable or selected can be tracked (and vice-versa). For example, this allows you to have an button cell in a table which does not change the selection, but can still be clicked on and tracked.
NSOutlineView.hReturns a Boolean value that indicates whether type select should proceed for a given event and search string.
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldTypeSelectForEvent:(NSEvent *)event withCurrentSearchString:(NSString *)searchString
The outline view that sent the message.
The event that caused the message to be sent.
The string for which searching is to proceed. The search string is nil if no type select has begun.
YES if type select should proceed, otherwise NO.
Generally, this method will be called from keyDown: and the event will be a key event.
NSOutlineView.hWhen the cursor pauses over a given cell, the value returned from this method is displayed in a tooltip.
- (NSString *)outlineView:(NSOutlineView *)ov toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
The outline view that sent the message.
The cell for which to generate a tooltip.
The proposed active area of the tooltip. To control the default active area, you can modify the rect parameter. By default, rect is computed as [cell drawingRectForBounds:cellFrame].
The table column that contains cell.
The item for which to display a tooltip.
The current mouse location in view coordinates.
If you don’t want a tooltip at that location, return nil or the empty string.
NSOutlineView.hReturns the string that is used for type selection for a given column and item.
- (NSString *)outlineView:(NSOutlineView *)outlineView typeSelectStringForTableColumn:(NSTableColumn *)tableColumn item:(id)item
The outline view that sent the message.
A table column in the outline view.
An item in the outline view.
The string that is used for type selection. You may want to change what is searched for based on what is displayed, or simply return nil for that row and/or column to not be searched
Implement this method if you want to control the string that is used for type selection. You may want to change what is searched for based on what is displayed, or simply return nil to specify that the given row and/or column should not be searched. By default, all cells with text in them are searched.
The default value when this delegate method is not implemented is:
[[outlineView preparedCellForColumn:tableColumn row:[outlineView rowForItem:item]] stringValue] |
and you can return this value from the delegate method if you wish.
NSOutlineView.hInforms the delegate that outlineView is about to display the cell specified by tableColumn and item.
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
The delegate can modify cell to alter its display attributes; for example, making uneditable values display in italic or gray text.
NSOutlineView.hInforms the delegate that an outline view is about to display a cell used to draw the expansion symbol.
- (void)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
Informs the delegate that outlineView is about to display cell—an expandable cell (a cell that has the expansion symbol)—for the column and item specified by tableColumn and item. The delegate can modify cell to alter its display attributes.
This method is not invoked when outlineView is about to display a non-expandable cell.
NSOutlineView.hInvoked when notification is posted—that is, whenever the user moves a column in the outline view.
- (void)outlineViewColumnDidMove:(NSNotification *)notification
This method is invoked as a result of posting an NSOutlineViewColumnDidMoveNotification.
NSOutlineView.hInvoked when notification is posted—that is, whenever the user resizes a column in the outline view.
- (void)outlineViewColumnDidResize:(NSNotification *)notification
This method is invoked as a result of posting an NSOutlineViewColumnDidResizeNotification.
NSOutlineView.hInvoked when notification is posted—that is, whenever the user collapses an item in the outline view.
- (void)outlineViewItemDidCollapse:(NSNotification *)notification
This method is invoked as a result of posting an NSOutlineViewItemDidCollapseNotification.
NSOutlineView.hInvoked when notification is posted—that is, whenever the user expands an item in the outline view.
- (void)outlineViewItemDidExpand:(NSNotification *)notification
This method is invoked as a result of posting an NSOutlineViewItemDidExpandNotification.
NSOutlineView.hInvoked when notification is posted—that is, whenever the user is about to collapse an item in the outline view.
- (void)outlineViewItemWillCollapse:(NSNotification *)notification
This method is invoked as a result of posting an NSOutlineViewItemWillCollapseNotification.
NSOutlineView.h