从NSTableView获取选定的列和行 [英] Get selected column and row from NSTableView
问题描述
我有一个有2列的表格.对于每一列,都从字典中包含的唯一数组中填充数据.因此,现在当我单击第二列中的一行时,由于我没有选择列",而只能选择行,因此无法从字典中提取数据.
[tableView selectedColumn]//返回-1[tableView selectedRow]//返回1,但是我也需要列号,以便可以从字典中选择数组.
如何获取选定的列?
如果您查看NSTableViewDelegate,则可以使用一些选项.
苹果最喜欢使用的是:
tableView:selectionIndexesForProposedSelection:",它为您提供了建议的"选择范围(即您可以跟踪的范围)作为NSIndexSet,但是<一个href ="https://stackoverflow.com/questions/5653033/problem-in-tableview">了解如何从NSIndexSet中提取NSIndexPaths可能有些棘手.
相反,您还可以通过处理委托方法来同时跟踪选定的行和选定的列:
和
tableView:shouldSelectTableColumn:"
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 ?
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:
and
"tableView:shouldSelectTableColumn:
"
这篇关于从NSTableView获取选定的列和行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!