您可以在NSTableView委托
selectedRowIndexes的
tableViewSelectionDidChange方法中使用tableView中的属性。
在此示例中,tableView允许多项选择。
迅捷3
func tableViewSelectionDidChange(_ notification: Notification) { if let myTable = notification.object as? NSTableView { // we create an [Int] array from the index set let selected = myTable.selectedRowIndexes.map { Int($0) } print(selected) }}迅捷2
func tableViewSelectionDidChange(notification: NSNotification) { var mySelectedRows = [Int]() let myTableViewFromNotification = notification.object as! NSTableView let indexes = myTableViewFromNotification.selectedRowIndexes // we iterate over the indexes using `.indexGreaterThanIndex` var index = indexes.firstIndex while index != NSNotFound { mySelectedRows.append(index) index = indexes.indexGreaterThanIndex(index) } print(mySelectedRows)}


