1
votes

When it comes to getting the data of an NSTableView which was selected, one gets the selected row, and compares it to the item in the same position in the data source.

However, I am reading data from different XML files and displaying it according to certain selections done on screen.

I would like to get the data that the user has selected directly from the NSTableView.

I know that this goes against the MVC model and all that, but I would appreciate an answer or some hint on how to do this.

1
If I don't find a solution, I'm going to create a separate class and have an instance of the class when a new object is to be added, and then use this new class when reading. Which will ultimately be a better model. However, I would still like to know if there is a solution to reading directly from an NSTableView. Thanks.Kevin
A table view doesn't have an internal cache of the data. The data source is that cache. That's the whole point. You have to get the data from the data source. There shouldn't be a problem doing that, though: [[tableView dataSource] tableView:tableView objectValueForTableColumn:theColumn row:theRow].Ken Thomases
Thanks, that makes a lot of sense and works. Didn't know that the language took care of keeping track of the data source even if no formal (single) one was defined. If you'd like to place your response as an answer I can mark it as such :) Thanks a lot!Kevin

1 Answers

1
votes

A table view doesn't have an internal cache of the data. The data source is that cache. That's the whole point. You have to get the data from the data source. There shouldn't be a problem doing that, though: [[tableView dataSource] tableView:tableView objectValueForTableColumn:theColumn row:theRow].

However, what do you mean when you say "Didn't know that [it] took care of keeping track of the data source even if no formal (single) one was defined"? Do you mean you're using bindings rather than setting up a data source? In that case, I wouldn't use this technique. The existence of a data source in that case would be an implementation detail. For the bindings case, you should directly access the array controller.