Get selected column and row from NSTableView

爱⌒轻易说出口 提交于 2019-12-10 11:36:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!