1

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 ?

GoodSp33d
  • 6,252
  • 4
  • 35
  • 67

1 Answers1

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:"

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Am using a view based table view, so each cell will load data from a dictionary. I have removed headers from table view, so these delegates are not getting invoked. I have set `table setAllowsColumnSelection:YES` as well. – GoodSp33d Nov 09 '13 at 07:47
  • why do you think "`tableView:shouldSelectRow:`" and "`tableView:shouldSelectTableColumn:`" should only work for non-view tables? I don't see that restriction in Apple's documentation. Do any NSTableViewDelegate methods work for you, or did you forget to set your table view's delegate? – Michael Dautermann Nov 09 '13 at 08:56
  • sorry that I didnt mention before, I have added table view programtically. Other delegates are working fine, but this one doesnt get invoked, so I thought column was not allowed to be selected and I added `setAllowColumnSelection:YES` to make it selectable but still these delegates wont get invoked. – GoodSp33d Nov 09 '13 at 09:40