在NSTableView(Swift)中选择行
我想让我的Mac应用程序在我的表视图中的某一行被选中时执行某些操作。在iOS中,当点击表格视图单元格时,我可以使用在NSTableView(Swift)中选择行,swift,macos,nstableview,Swift,Macos,Nstableview,我想让我的Mac应用程序在我的表视图中的某一行被选中时执行某些操作。在iOS中,当点击表格视图单元格时,我可以使用didSelectRowAt执行某些操作: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { //Some code } 在iOS中,当点击表视图单元格时,将执行didSelectRowAt。如何在macOS中使用NSTableView执行类似操作?有两个选项: 执
didSelectRowAt
执行某些操作:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//Some code
}
在iOS中,当点击表视图单元格时,将执行didSelectRowAt
。如何在macOS中使用NSTableView执行类似操作?有两个选项:
NSTableViewDelegate
并检查或SelectionIndex
绑定到dynamic
var类型的IndexSet
并使用didSet
观察者三。观察
NSTableViewSelectionDidChangeNotification
。并选中selectedRow
或selectedRowIndexes
@Willeke,从技术上讲,这与1相同。您必须添加观察者。观察者不必是代理。