GoodSp33d
GoodSp33d

Reputation: 6282

Get selected column and row from NSTableView

I have a table with 2 columns. And for each column am populating data from an unique array which is contained in a dictionary. So now when I click on a row in second column, its not possible to extract data from the dictionary as I dont get Column selected, but only row.

[tableView selectedColumn] //returns -1
[tableView selectedRow] //returns 1, but I needed the column number as well so I could pick the array from dictionary.

How can I get the column selected ?

Upvotes: 1

Views: 2420

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89509

If you look in NSTableViewDelegate, you have a few options you can take advantage of.

Apple's most preferred one to use is:

"tableView:selectionIndexesForProposedSelection:", which gives you the "proposed" selection range (i.e. something you can keep track of) as a NSIndexSet, but it can be a bit tricky to understand how to extract NSIndexPaths from a NSIndexSet.

Instead, you can also keep track of both the selected row and selected column by handling the delegate methods:

"tableView:shouldSelectRow:"

and

"tableView:shouldSelectTableColumn:"

Upvotes: 1

Related Questions