从NSTableView获取选定的列和行 [英] Get selected column and row from NSTableView

查看:119
本文介绍了从NSTableView获取选定的列和行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有2列的表格.对于每一列,都从字典中包含的唯一数组中填充数据.因此,现在当我单击第二列中的一行时,由于我没有选择列",而只能选择行,因此无法从字典中提取数据.

  [tableView selectedColumn]//返回-1[tableView selectedRow]//返回1,但是我也需要列号,以便可以从字典中选择数组. 

如何获取选定的列?

解决方案

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

苹果最喜欢使用的是:

tableView:selectionIndexesForProposedSelection:",它为您提供了建议的"选择范围(即您可以跟踪的范围)作为NSIndexSet,但是<一个href ="https://stackoverflow.com/questions/5653033/problem-in-tableview">了解如何从NSIndexSet中提取NSIndexPaths可能有些棘手.

相反,您还可以通过处理委托方法来同时跟踪选定的行和选定的列:

tableView:shouldSelectRow:"

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:

"tableView:shouldSelectRow:"

and

"tableView:shouldSelectTableColumn:"

这篇关于从NSTableView获取选定的列和行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆