Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set doubleAction property of NSTableViewCell in Swift?

Tags:

swift

cocoa

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).

like image 427
someguy234 Avatar asked Mar 20 '15 04:03

someguy234


2 Answers

I was forgetting this: tableView?.target = self

It works perfectly now!

like image 71
someguy234 Avatar answered Sep 29 '22 23:09

someguy234


Swift 4

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

@objc func tableViewDoubleAction(sender: AnyObject) {
    print("row double clicked")
}
like image 21
Nick K9 Avatar answered Sep 29 '22 23:09

Nick K9