怎么知道在Swift里面'tableViewSelectionDidChange:'里面NSTableView里面的selection做了什么变化呢?
How to learn in Swift inside 'tableViewSelectionDidChange:' in which NSTableView the selection did change?
我有一个 macOS 项目,其中有两个 tableView 与 delegate 具有相同的 viewControl。我如何了解在 tableViewSelectionDidChange:?
上调用了两者中的哪一个
编辑:我正在使用 tableViewSelectionDidChange:
来防止某些我用作 "title group" 的项目被点击。
我读了这个问题 NSTableViewDelegate with 2 tables and tableViewSelectionDidChange:(NSNotification *)aNotification 但作为初学者,我不知道如何在 Swift 中做到这一点。
我试过了
func tableViewSelectionDidChange(_ notification: Notification) {
let tableViewName = (notification.object? as AnyObject).identifier // error
if tableViewName == myTableView1 {
print("myTableView1")
}
}
但我收到 "Ambiguous use of Identifier" 错误。有人这么好心告诉我我做错了什么吗?一个工作示例将不胜感激。
来自 NSTableViewSelectionDidChangeNotification
的文档
The notification object is the table view whose selection changed. This notification does not contain a userInfo dictionary.
所以这个对象显然是非可选的并且是一个 table 视图实例。 不是AnyObject
let tableView = notification.object as! NSTableView
if let identifier = tableView.identifier, identifier == "myTableView1" {
print("myTableView1")
}
我有一个 macOS 项目,其中有两个 tableView 与 delegate 具有相同的 viewControl。我如何了解在 tableViewSelectionDidChange:?
上调用了两者中的哪一个编辑:我正在使用 tableViewSelectionDidChange:
来防止某些我用作 "title group" 的项目被点击。
我读了这个问题 NSTableViewDelegate with 2 tables and tableViewSelectionDidChange:(NSNotification *)aNotification 但作为初学者,我不知道如何在 Swift 中做到这一点。
我试过了
func tableViewSelectionDidChange(_ notification: Notification) {
let tableViewName = (notification.object? as AnyObject).identifier // error
if tableViewName == myTableView1 {
print("myTableView1")
}
}
但我收到 "Ambiguous use of Identifier" 错误。有人这么好心告诉我我做错了什么吗?一个工作示例将不胜感激。
来自 NSTableViewSelectionDidChangeNotification
的文档The notification object is the table view whose selection changed. This notification does not contain a userInfo dictionary.
所以这个对象显然是非可选的并且是一个 table 视图实例。 不是AnyObject
let tableView = notification.object as! NSTableView
if let identifier = tableView.identifier, identifier == "myTableView1" {
print("myTableView1")
}