Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Next Page > Hide TOC

NSTableView Class Reference

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

Class at a Glance

An NSTableView object displays record-oriented data in a table and allows the user to edit values and resize and rearrange columns.

Principal Attributes

Commonly Used Methods

dataSource

Returns the object providing the data that the table view displays.

tableColumns

Returns the NSTableColumn objects representing attributes for the table view.

selectedColumn

Returns the index of the selected column.

selectedRow

Returns the index of the selected row.

numberOfRows

Returns the number of rows in the table view.

reloadData

Informs the table view that data has changed and needs to be retrieved and displayed again.

Overview

An NSTableView object displays data for a set of related records, with rows representing individual records and columns representing the attributes of those records.

A table view is usually displayed in a scroll view, like this:


"Tableview example"

A table 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). You should not, therefore, try to directly set data values programmatically in the table view; instead you should modify the values in the data source and allow the changes to be reflected in the table view. See the NSTableDataSource informal protocol, which declares the methods that an NSTableView object uses to access the contents of its data source object.

Adopted Protocols

NSUserInterfaceValidations

Tasks

Setting the Data Source

Loading Data

Target-action Behavior

Configuring Behavior

Setting Display Attributes

Column Management

Selecting Columns and Rows

Table Dimensions

Displaying Cell

Editing Cells

Setting Auxiliary Views

Layout Support

Drawing

Scrolling

Persistence

Selecting in the Tableview

Setting the Delegate

Highlightable Column Headers

Dragging

Sorting

Moving and Resizing Columns

Responding to Mouse Events

Text Delegate Methods

Displaying Tooltips

Deprecated Methods

Instance Methods

addTableColumn:

Adds a given column as the last column of the receiver.

- (void)addTableColumn:(NSTableColumn *)aColumn

Parameters
aColumn

The column to add to the receiver.

Availability
See Also
Declared In
NSTableView.h

allowsColumnReordering

Returns a Boolean value that indicates whether the receiver allows the user to rearrange columns by dragging their headers.

- (BOOL)allowsColumnReordering

Return Value

YES to allow the user to rearrange columns by dragging their headers, otherwise NO.

Discussion

The default is YES. You can rearrange columns programmatically regardless of this setting.

Availability
See Also
Declared In
NSTableView.h

allowsColumnResizing

Returns a Boolean value that indicates whether the receiver allows the user to resize columns by dragging between their headers.

- (BOOL)allowsColumnResizing

Return Value

YES if the receiver allows the user to resize columns by dragging between their headers, otherwise NO.

Discussion

The default is YES. You can resize columns programmatically regardless of this setting.

Availability
See Also
Declared In
NSTableView.h

allowsColumnSelection

Returns a Boolean value that indicates whether the receiver allows the user to select columns by clicking their headers.

- (BOOL)allowsColumnSelection

Return Value

YES if the receiver allows the user to select columns by clicking their headers, otherwise NO.

Discussion

The default is NO. You can select columns programmatically regardless of this setting.

Availability
See Also
Declared In
NSTableView.h

allowsEmptySelection

Returns a Boolean value that indicates whether the receiver allows the user to select zero columns or rows.

- (BOOL)allowsEmptySelection

Return Value

YES if the receiver allows the user to select zero columns or rows, otherwise NO.

Discussion

The default is YES.

You cannot set an empty selection programmatically if this setting is NO, unlike with the other settings that affect selection behavior.

Availability
See Also
Declared In
NSTableView.h

allowsMultipleSelection

Returns a Boolean value that indicates whether the receiver allows the user to select more than one column or row at a time.

- (BOOL)allowsMultipleSelection

Return Value

YES if the receiver allows the user to select more than one column or row at a time, otherwise NO.

Discussion

The default is NO. You can select multiple columns or rows programmatically regardless of this setting.

Availability
See Also
Declared In
NSTableView.h

allowsTypeSelect

Returns a Boolean value that indicates whether the receiver allows the user to type characters to select rows.

- (BOOL)allowsTypeSelect

Return Value

YES if the receiver allows type selection, otherwise NO.

Discussion

The default value is YES.

Availability
See Also
Declared In
NSTableView.h

autoresizesAllColumnsToFit

Returns YES if the receiver proportionally resizes its columns to fit when its superview’s frame changes, NO if it only resizes the last column. (Deprecated. Use columnAutoresizingStyle instead.)

- (BOOL)autoresizesAllColumnsToFit

Availability
See Also
Declared In
NSTableView.h

autosaveName

Returns the name under which table information is automatically saved.

- (NSString *)autosaveName

Return Value

The name under which table information is automatically saved. If no name has been set, returns nil.

Discussion

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

Note that even when a table view has an autosave name, it may not be saving table information automatically. To check whether table information is being saved automatically, use autosaveTableColumns.

Availability
See Also
Declared In
NSTableView.h

autosaveTableColumns

Returns a Boolean value that indicates whether the order and width of the receiver’s columns are automatically saved.

- (BOOL)autosaveTableColumns

Discussion

The table 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 table information isn’t saved.

Availability
See Also
Declared In
NSTableView.h

backgroundColor

Returns the color used to draw the background of the receiver.

- (NSColor *)backgroundColor

Return Value

The color used to draw the background of the receiver.

Discussion

The default background color is light gray.

Availability
See Also
Declared In
NSTableView.h

canDragRowsWithIndexes:atPoint:

Returns whether the receiver allows dragging the rows at rowIndexes with a drag initiated at mousedDownPoint.

- (BOOL)canDragRowsWithIndexes:(NSIndexSet *)rowIndexes atPoint:(NSPoint)mouseDownPoint

Discussion

Return NO to disallow the drag.

Availability
Declared In
NSTableView.h

clickedColumn

Returns the index of the column the user clicked to trigger an action message.

- (NSInteger)clickedColumn

Return Value

The index of the column the user clicked to trigger an action message. Returns –1 if the user clicked in an area of the table view not occupied by columns.

Discussion

The return value of this method is meaningful only in the target’s implementation of the action or double-action method.

Availability
See Also
Declared In
NSTableView.h

clickedRow

Returns the index of the row the user clicked to trigger an action message.

- (NSInteger)clickedRow

Return Value

The index of the row the user clicked to trigger an action message. Returns –1 if the user clicked in an area of the table view not occupied by table rows.

Discussion

The return value of this method is meaningful only in the target’s implementation of the action or double-action method.

Availability
See Also
Declared In
NSTableView.h

columnAtPoint:

Returns the index of the column a given point lies in.

- (NSInteger)columnAtPoint:(NSPoint)aPoint

Parameters
aPoint

A point in the coordinate system of the receiver.

Return Value

The index of the column aPoint lies in, or –1 if aPoint lies outside the receiver’s bounds.

Availability
See Also
Declared In
NSTableView.h

columnAutoresizingStyle

Returns the receiver’s column autoresizing style.

- (NSTableViewColumnAutoresizingStyle)columnAutoresizingStyle

Return Value

The receiver’s column autoresizing style. For possible values, see “Autoresizing Styles.”

Availability
See Also
Declared In
NSTableView.h

columnIndexesInRect:

Returns the indexes of the receiver’s columns that intersect the specified rectangle.

- (