How to set doubleAction property for NSTableViewCell in Swift?

I am trying to add a double-click listener to mine NSTableViewfor each cell. Wherever I searched, it seems like this is done with help @selector, and all the source code was in Objective-C. I tried converting this code to Swiftto assign a method doubleActionto mine NSTableView, but it does not work (since my method is not 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).

+4
source share
2 answers

I forgot about this: tableView?.target = self

Now it works great!

+4
source

Swift 4

override func viewDidLoad() {
    table.target = self
    table.doubleAction = #selector(tableViewDoubleAction)
}

@objc func tableViewDoubleAction(sender: AnyObject) {
    print("row double clicked")
}
+1
source

All Articles