In NSTableViewDataSource, the overview says that tableView:objectValueForTableColumn:row: is "required".

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

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

Note: This method is mandatory unless your application is using Cocoa bindings for providing data to the table view.

but unlike other methods makes no mention of being unnecessary for view-based tables.

And yet, if it is required, I can't figure out what it's used for. If so, what's the relationship between that and -tableView:viewForTableColumn:row:, which also takes a table, column, and row, and returns the thing to display there?

In some brief testing, it looks like NSTableView will use -tableView:objectValueForTableColumn:row: if it's defined, and if not, it'll use -tableView:viewForTableColumn:row:. If they're both defined, it calls them both, but only uses the former for display.

If I'm writing a view-based NSTableView, is there any reason to implement this method?

有帮助吗?

解决方案

No, despite all of the documentation saying that it is "mandatory" and "required", the NSTableView.h header file says:

This method is required for the "Cell Based" TableView, and is optional for the "View Based" TableView.

If you implement -tableView:viewForTableColumn:row: to do all the necessary work to display your data, you don't need to implement the other method.

The header file also says why you might implement it for view-based tables:

If implemented in the latter case, the value will be set to the view at a given row/column if the view responds to -setObjectValue: (such as NSControl and NSTableCellView).

This doesn't seem any easier than just implementing it in the normal view-based method, though, so it seems more like an upgrade-compatibility feature than something you'd actually want to use in a new application.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top