Is -tableView: objectValueForTableColumn: string: required?

The NSTableViewDataSource review says that tableView:objectValueForTableColumn:row: "required."

Next to this, it says that tableView:setObjectValue:forTableColumn:row: is only required for "cell-only tables", which means that the person writing this document knew about view-based tables and that tableView:objectValueForTableColumn:row: required to represent the table.

The documentation for the tableView:objectValueForTableColumn:row: method itself says:

Note This method is required if your application does not use Cocoa bindings to provide table data.

but unlike other methods does not mention that for tables based on viewing, there is no need.

And yet, if it is required, I cannot understand what it is used for. If so, what is the relationship between this and -tableView:viewForTableColumn:row: which also takes a table, column and row and returns the thing displayed there?

In some brief testing, it looks like NSTableView will use -tableView:objectValueForTableColumn:row: if it is defined, and if not, it will use -tableView:viewForTableColumn:row: If they are both defined, they call them both, but only the first is used for display.

If I write an NSTableView based on a view, are there any reasons for implementing this method?

+6
source share
1 answer

No , despite all the documentation that says it is โ€œrequiredโ€ and โ€œrequired,โ€ the NSTableView.h header file says:

This method is required for a Cell based TableView and is optional for a View based TableView.

If you implement -tableView:viewForTableColumn:row: to do all the necessary work to display your data, you do not need to implement another method.

The header file also says why you can implement it for tables based on the view:

If this is implemented in the latter case, the value will be set in the view in this row / column if the view responds to -setObjectValue: (for example, NSControl and NSTableCellView).

It doesn't seem easier than just implementing it in a regular view-based method, however, it seems like an update compatibility function than what you really would like to use in a new application.

+5
source

All Articles