Double click an NSTableView row in Cocoa?

Viewed 30890

I need my application to open a window when a user double clicks on a row in an NSTableView. I'm having a bit of a difficult time finding information or examples on how to accomplish this. Can anybody point me in the right direction?

8 Answers

Take a look at the -setDoubleAction: method on NSTableView; you can set that to a method that will be called just like the normal target-action system but on a double-click.

In that action method, -clickedRow will be useful.

Updated Alfred's answer for Swift 5

@IBOutlet weak var searchResultTable: NSTableView!

override func viewDidLoad() {
    super.viewDidLoad()
    searchResultTable.target = self
    searchResultTable.doubleAction = #selector(doubleClickOnResultRow)
}

@objc func doubleClickOnResultRow()
{
    print("doubleClickOnResultRow \(searchResultTable.clickedRow)")
}
Related