从NSTableView获取选定的列和行

时间:2013-11-09 06:36:57

标签: macos nstableview

我有一个包含2列的表格。并且对于每个列,我将从包含在字典中的唯一数组中填充数据。所以现在当我点击第二列中的一行时,它不可能从字典中提取数据,因为我没有选择Column,而只是选择了行。

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

如何选择列?

1 个答案:

答案 0 :(得分:1)

如果您查看NSTableViewDelegate,您可以使用一些选项。

Apple最喜欢使用的是:

"tableView:selectionIndexesForProposedSelection:",它为您提供“建议的”选择范围(即您可以跟踪的内容)作为NSIndexSet,但是it can be a bit tricky to understand how to extract NSIndexPaths from a NSIndexSet

相反,您还可以通过处理委托方法跟踪两者所选行和所选列:

"tableView:shouldSelectRow:"

"tableView:shouldSelectTableColumn:"