【问题标题】:Getting NSTableView row index of focussed row?获取焦点行的 NSTableView 行索引?
【发布时间】:2015-05-29 13:25:24
【问题描述】:

如何获取NSTableView 中当前正在关注的行的索引?左键单击时选择了该行,但右键单击该行时我需要索引,即当用户在其上打开上下文菜单但该行确实获得焦点时,可能不会选择该行。我在文档中找不到有关如何执行此操作的任何详细信息。

【问题讨论】:

    标签: macos swift cocoa nstableview


    【解决方案1】:

    您可以从tableView.clickedRow 获取右击行的索引。请注意,如果用户右键单击选定(突出显示)的行,系统将“聚焦”所有选定的行(前提是有多个选定的行;您可以在 Finder 中尝试)。因此,您可能也需要考虑到这一点。

    可能的实现:

    int clickedRow = tableView.clickedRow;
    NSIndexSet *focusedIndexes;
    if (clickedRow != -1) {
        if ([tableView isRowSelected:clickedRow]) {
            focusedIndexes = tableView.selectedRowIndexes;
        } else {
            focusedIndexes = [NSIndexSet indexSetWithIndex:clickedRow];
        }
        // do what you desire with focusedIndexes
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      相关资源
      最近更新 更多