如何获取NSTableView中当前选定的行和列的索引

问题描述:

我正在使用超简单的NSTableView开发一个小型MacOS应用程序. 当用户选择一个单元格时,我需要知道该单元格的列和行索引. 我已经实现了该方法

I'm working on a small MacOS app with a super simple NSTableView. When the user select a cell I need to know the column and the row index of this cell. I've implemented the method

- (void)tableViewSelectionDidChange:(NSNotification *)notification

并向NSTableView询问selectedColumnselectedRow,但是当我单击表时,结果始终是选择整个Row. (实际上selectedRow返回正确的索引号,而selectedColumn返回-1 =无选择)

and ask to the NSTableView for selectedColumn and selectedRow, but when I click on the table the result is always the selection of an entire Row. (in fact selectedRow return the right index number and selectedColumn return -1 = no selection)

如何选择一个单元格以及如何知道他的坐标?

感谢您的帮助!

所选行

对于网格或电子表格类型的布局,最好使用NSCollectionView.

For a grid or spreadsheet type layout it is better to use an NSCollectionView.

有关详细信息,请参见文档.

See the documentation for more info.