< Previous PageNext Page > Hide TOC

Using a Table Delegate

In addition to the delegate methods used by other controls, a table view object has several table-specific delegate methods. 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 alter the selection or edit a value are invoked during user actions that affect the NSTableView 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, send the appropriate message (checking first that the delegate responds to that message).

Note: Because the delegate methods involve data displayed by the NSTableView object, the delegate is typically the same object as the data source. For more information about data source objects, see “Using a Table Data Source.”

The delegate can manage much of the table view behavior by implementing the following methods:

Delegate method

Description

tableView:willDisplayCell:forTableColumn:row:

Informs the delegate that the NSTableView object is about to draw a particular cell. The delegate can modify the provided NSCell object to alter the display attributes for that cell; for example, it could make uneditable values display in italic or gray text

tableView:shouldSelectRow: and tableView:shouldSelectTableColumn:

These methods give the delegate control over whether the user can select a particular row or column (though the user can still reorder columns). This is useful for disabling particular rows or columns. For example, in a database client application, when another user is editing a record you might want to prevent other users from selecting the row containing that record.

selectionShouldChangeInTableView:

Allows the delegate to deny a change in selection; 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.

tableView:shouldEditTableColumn:row:

Asks the delegate whether it is permitted to edit a particular cell. The delegate can approve or deny the request.

In addition to these methods, the delegate is also automatically registered to receive messages corresponding to NSTableView notifications. These messages inform the delegate when the selection changes and when a column is moved or resized:

Delegate Message

Notification

tableViewColumnDidMove:

NSTableViewColumnDidMoveNotification

tableViewColumnDidResize:

NSTableViewColumnDidResizeNotification

tableViewSelectionDidChange:

NSTableViewSelectionDidChangeNotification

tableViewSelectionIsChanging:

NSTableViewSelectionIsChangingNotification



< Previous PageNext Page > Hide TOC


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


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.