I am trying to add a double click listener to my NSTableView
for each cell. Everywhere I searched it seems to be done using a @selector
and all the source code was in Objective-C
. I tried to convert that code to Swift
to assign the doubleAction
method to my NSTableView
however it's not working (as my method is not getting called).
@IBOutlet var tableView:NSTableView?
override func awakeFromNib() {
let clSelector:Selector = "dblClk:"
tableView?.doubleAction = clSelector
}
func dblClk(sender:AnyObject){
println("ran")
}
Also my tableView has custom cells (in case that matters).
I was forgetting this:
tableView?.target = self
It works perfectly now!
Swift 4
override func viewDidLoad() {
table.target = self
table.doubleAction = #selector(tableViewDoubleAction)
}
@objc func tableViewDoubleAction(sender: AnyObject) {
print("row double clicked")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With