A set of methods that a table view uses to provide data to a table view and to allow the editing of the table view's data source object.


Some of the methods in this protocol, such as tableView(_:objectValueFor:row:) and numberOfRows(in:) along with other methods that return data, are called frequently, so they must be efficient.

If you’re not using Cocoa bindings to provide data to the table view, the following methods are required:

To learn more about Cocoa bindings, see Cocoa Bindings Programming Topics.


Getting Values

func numberOfRows(in: NSTableView)

Returns the number of records managed for aTableView by the data source object.

func tableView(NSTableView, objectValueFor: NSTableColumn?, row: Int)

Called by the table view to return the data object associated with the specified row and column.

Setting Values

func tableView(NSTableView, setObjectValue: Any?, for: NSTableColumn?, row: Int)

Sets the data object for an item in the specified row and column.

Implementing Pasteboard Support

func tableView(NSTableView, pasteboardWriterForRow: Int)

Called to allow the table to support multiple item dragging.

Drag and Drop

func tableView(NSTableView, acceptDrop: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation)

Called by aTableView when the mouse button is released over a table view that previously decided to allow a drop.

func tableView(NSTableView, namesOfPromisedFilesDroppedAtDestination: URL, forDraggedRowsWith: IndexSet)

Returns an array of filenames that represent the indexSet rows for a drag to dropDestination.

func tableView(NSTableView, writeRowsWith: IndexSet, to: NSPasteboard)

Returns a Boolean value that indicates whether a drag operation is allowed.

func tableView(NSTableView, updateDraggingItemsForDrag: NSDraggingInfo)

Implement this method to allow the table to update dragging items as they are dragged over a view.


func tableView(NSTableView, sortDescriptorsDidChange: [NSSortDescriptor])

Called by aTableView to indicate that sorting may need to be done.


Inherits From

See Also


protocol NSTableViewDelegate

A set of optional methods you implement in a table view delegate to customize the behavior of the table view.