NSTableView
A set of related records, displayed in rows that represent individual records and columns that represent the attributes of those records.
Declaration
class NSTableViewOverview
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
makeView(withIdentifier:owner:)rowView(atRow:makeIfNecessary:)view(atColumn:row:makeIfNecessary:)NSUserInterfaceItemIdentifier
Updating the Table View Arrangement
beginUpdates()endUpdates()moveRow(at:to:)insertRows(at:withAnimation:)removeRows(at:withAnimation:)row(for:)column(for:)
NSView-Based Table Nib File Registration
Target-action Behavior
Configuring Behavior
allowsColumnReorderingallowsColumnResizingallowsMultipleSelectionallowsEmptySelectionallowsColumnSelectionusesAutomaticRowHeights
Setting Display Attributes
intercellSpacingrowHeightbackgroundColorusesAlternatingRowBackgroundColorsstyleeffectiveStyleNSTableView.StyleselectionHighlightStylegridColorgridStyleMaskindicatorImage(in:)setIndicatorImage(_:in:)
Getting and Setting Row Size Styles
Column Management
addTableColumn(_:)removeTableColumn(_:)moveColumn(_:toColumn:)tableColumnscolumn(withIdentifier:)tableColumn(withIdentifier:)
Selecting Columns and Rows
selectColumnIndexes(_:byExtendingSelection:)selectedColumnselectedColumnIndexesdeselectColumn(_:)numberOfSelectedColumnsisColumnSelected(_:)selectRowIndexes(_:byExtendingSelection:)selectedRowselectedRowIndexesdeselectRow(_:)numberOfSelectedRowsisRowSelected(_:)selectAll(_:)deselectAll(_:)
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
userInterfaceLayoutDirectionrect(ofColumn:)rect(ofRow:)rows(in:)columnIndexes(in:)column(at:)row(at:)frameOfCell(atColumn:row:)columnAutoresizingStylesizeLastColumnToFit()noteNumberOfRowsChanged()tile()sizeToFit()noteHeightOfRows(withIndexesChanged:)
Drawing
Scrolling
Table Column State Persistence
Accessing the Delegate
Highlightable Column Headers
Dragging
dragImageForRows(with:tableColumns:event:offset:)canDragRows(with:at:)setDraggingSourceOperationMask(_:forLocal:)verticalMotionCanBeginDragdraggingDestinationFeedbackStylesetDropRow(_:dropOperation:)
Sorting
Row Actions
Hiding and Showing Table Rows
Deprecated Methods
focusedColumn()setFocusedColumn(_:)shouldFocusCell(_:atColumn:row:)performClickOnCell(atColumn:row:)preparedCell(atColumn:row:)
Constants
Specifying a Custom Row View in a Nib FileNSTableView.DraggingDestinationFeedbackStyleNSTableView.DropOperationNSTableView.GridLineStyleNSTableView.ColumnAutoresizingStyleNSTableView.SelectionHighlightStyleNSTableView.AnimationOptionsNSTableView.RowSizeStyleNSTableView.RowActionEdge
Notifications
See Also
Related Documentation
- Table View Programming Guide for Mac