问题
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 ?
回答1:
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:"
来源:https://stackoverflow.com/questions/19873180/get-selected-column-and-row-from-nstableview