在基于视图的nstable中获取选定的行和列 [英] Get selected row and column in view based nstable

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

问题描述

我有一个基于视图的NSTable具有十行或更多的行和五列。要填充此表的数据,我有一个5个数组的字典。所以每个字典对象是为每列。

I have a view based NSTable with ten or more rows and five columns. To populate data for this table, I have a dictionary of 5 arrays. So each dictionary object is for each column.

现在我需要在点击任何单元格时获取信息。我使用 tableViewSelectionDidChange 委托获得单元格选择的通知。使用这个我可以得到只有 [myTableView selectedRow] 才能知道选择的行。我如何知道行在哪一列。例如:我选择/单击第3列的第5行。现在我需要知道它点击了哪个列,以便我可以从字典中提取所需的对象。

Now I need to get information when I click on any cell. I am using tableViewSelectionDidChange delegate to get notified on cell selection. Using this I can get only the [myTableView selectedRow] to get to know the row selected. How can I know which column was the row in. For ex: I select/click on 5th row in 3rd column. Now I need to know which column was it clicked on so that I can extract required object from the dictionary.

任何线索?

推荐答案

您可以覆盖mouseDown:event您的tableView并获得点击的列为:

You may override the mouseDown: event of your tableView and get the clicked column as:

- (void)mouseDown:(NSEvent *)theEvent
  {

      NSPoint globalLocation = [theEvent locationInWindow];
      NSPoint localLocation = [self convertPoint:globalLocation fromView:nil];

      NSInteger clickedCol = [self columnAtPoint:localLocation];

      [super mouseDown:theEvent];
  }

或者您可以使用NSTableView委托方法:

or you may use NSTableView delegate method:

 tableView:didClickTableColumn:

参考检查:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSTableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSTableViewDelegate/tableView: didClickTableColumn

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

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