如何在NSTableView中获得前面选定的行索引
方法
func tableViewSelectionIsChanging(notification: NSNotification) {
let index = (notification.object as! NSTableView).selectedRow
println(index)
}func tableViewSelectionDidChange(notification: NSNotification)
let index = (notification.object as! NSTableView).selectedRow
println(index)
}两种方法都打印相同的值。如何获得由于选择而发生更改的索引/行?
或者简单地说,我如何做一个像这样的语句?
println("\(Selection changed from \(tableView.oldSelectedIndex) to \(tableView.newSelectionIndex)")发布于 2016-01-30 14:29:09
在选择单元格之前,在func tableView(tableView: NSTableView, shouldSelectRow row: Int)上调用函数delegate。在这里,您可以看到当前选定的行和建议的选择。
func tableView(tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
// This is the next index
NSLog("Next index: \(row)")
// Make sure that a row is currently selected!
guard self.tableView.selectedRowIndexes.count > 0 else {
return true
}
// Get the currently selected row.
let index = self.tableView.selectedRow
NSLog("Previous index: \(index)")
return true
}注:这并不能完全回答你的问题,因为你要求在新的选择发生后进行更改,而这只是在之前。不过,我希望这是足够的。
发布于 2015-08-16 03:30:12
你可以让它通过
tableView.selectedRowhttps://stackoverflow.com/questions/31997557
复制相似问题