Contents

NSTableView

A set of related records, displayed in rows that represent individual records and columns that represent the attributes of those records.

Declaration

class NSTableView

Overview

Table views are displayed in scroll views. Beginning with macOS v10.7, you can use NSView objects (most commonly customized NSTableCellView objects) instead of cells for specifying rows and columns. You can still use NSCell objects for each row and column item if you prefer.

A table view does not store its own data; it retrieves data values as needed from a data source to which it has a weak reference. You should not, therefore, directly set data values programmatically in the table view; instead, modify the values in the data source and allow the changes to be reflected in the table view. To learn about the methods that an NSTableView object uses to provide and access the contents of its data source object, see NSTableViewDataSource.

To customize a table view’s behavior without subclassing NSTableView, use the methods defined by the NSTableViewDelegate protocol. For example, the delegate supports table column management, type-to-select functionality, row selection and editing, custom tracking, and custom views for individual columns and rows. To learn more about the table view delegate, see NSTableViewDelegate.

Subclassing

Subclassing NSTableView is usually not necessary. Instead, you customize the table view using a delegate object (an object conforming to the NSTableViewDelegate protocol) and a data source object (conforming to the NSTableViewDataSource protocol), or by subclassing one of the following subcomponents: cells (when using NSCell-based table views), the row cell view or the row view (when using NSView-based table views), the table column class, or table column header classes.

Enabling the Table View

Use the isEnabled property to enable or disable the table view, which the view inherits from NSControl. This property affects the visual appearance of the table view differently depending on whether you use a view- or a cell-based table view. When you change the property’s value for a cell-based table view, the system manages the visual appearance of that table view’s rows, and updates them to a state that reflects the value. Because view-based table views permit complex items in their cells, it’s the developer’s responsibility to update each cell’s appearance as appropriate.

Topics

Creating a Table

Managing the Table’s Data

Creating Views to Display

Updating the Table View Arrangement

NSView-Based Table Nib File Registration

Target-action Behavior

Configuring Behavior

Setting Display Attributes

Getting and Setting Row Size Styles

Column Management

Selecting Columns and Rows

Enumerating Table Rows

Managing Type Select

Table Dimensions

Getting and Setting Floating Rows

Editing Cells

Adding and Deleting Row Views

Setting Auxiliary Views

Layout Support

Drawing

Scrolling

Table Column State Persistence

Accessing the Delegate

Highlightable Column Headers

Dragging

Sorting

Row Actions

Hiding and Showing Table Rows

Deprecated Methods

Constants

Notifications

See Also

Related Documentation

  • Table View Programming Guide for Mac

Views