Reputation: 4758
I have an NSTableView
with two columns and a data source that fills it with data. That part works.
How do I get data (NSString
format) out of the NSTableView
? I can get the selected row but NSTableView
doesn't seem to have methods for accessing data.
Getting the data from my data source seems to return useless data (type id and NSLog()
and NSRunAlertPanel()
both claim that the data isn't of the type NSString
.
What's the easiest way to get data from an NSTableView
?
Update:
Turns out the reason getting data from my data source fails has to do with the returning NSString
being part of an NSArray
in the tableView()
method.
My input file contains lines which I split up for the columns in my table view. The NSTableView
gets the correct data but when I call the tableView()
method myself I run into a EXC_BAD_ACCESS error which I assume has to do with memory management.
Another update:
It wasn't memory management. It was my application's inability to identify the NSTableColumn
it wanted. I wrote a second method to access data manually which uses an int for the column rather than a NSTableColumn
and that worked.
Upvotes: 3
Views: 2643
Reputation: 224864
It's a violation of the MVC paradigm to be using your table (a View) as a place to store your data (Model). You should be able to get the value from your data source the same way the table view does; what does your code for tableView:objectValueForTableColumn:row:
do to get the data?
If your table is editable, you will get calls from the table view to tableView:setObjectValue:forTableColumn:row:
to allow you to modify your data source appropriately.
Upvotes: 9