Saturn
Saturn

Reputation: 18149

Getting NSTableView's selected string

My NSTableView lists some strings. I managed to fill the list with strings and react whenever the user selects a new option. However, I am having trouble getting the string that is being chosen. Any ideas?

Upvotes: 0

Views: 382

Answers (2)

Francis McGrew
Francis McGrew

Reputation: 7272

I would suggest you take a look at the NSTableViewDelegate protocol. The table view notifies its delegate when the selection chages by calling tableViewSelectionDidChange:. You can implement that method, ask the table view which row(s) are selected and pull the relevant data from your datasource array.

Upvotes: 1

jrturton
jrturton

Reputation: 119242

Assuming your strings are being held in an array (dataSourceArray) which you are using as the table's (tableView) data source:

NSString *selectedStringValue = [dataSourceArray objectAtIndex:[tableView selectedRow]];

If you are doing anything more complicated than that you will have to add more detail to your question, perhaps how you are deriving the values in the first place?

Upvotes: 2

Related Questions