NSTableView所选行(Swift) [英] NSTableView selected row (Swift)

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

问题描述

我有一个 NSTableView 。我想打印用户点击的行的行号。我不知道我应该从这开始。是否有一个方法?

I have a NSTableView with one column. I would like to print the row number of the row that the user has clicked on. I am not sure where I should start with this. Is there a method for this?

推荐答案

您可以在TableView委托中的tableViewSelectionDidChange中使用selectedRowIndexes >

You can use "selectedRowIndexes" in "tableViewSelectionDidChange" in your TableView delegate:

func tableViewSelectionDidChange(notification: NSNotification) {
    var mySelectedRows = [Int]()
    let myTableViewFromNotification = notification.object as! NSTableView
    // In this example, the TableView allows multiple selection
    let indexes = myTableViewFromNotification.selectedRowIndexes
    var index = indexes.firstIndex
    while index != NSNotFound {
        mySelectedRows.append(index)
        index = indexes.indexGreaterThanIndex(index)
    }
    print(mySelectedRows)
}

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

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