How to catching doubleClick events from NSOutlineV

2019-09-14 01:33发布

问题:

I am trying to catch doubleClick events from my NSOutlineView to be passed to my ViewController. My idea is to catch doubleClick events and to get the selected row from my OutlineView What I did so far was subclassing the NSOutlineView in order to overwrite mouseDown

override func mouseDown(with event: NSEvent) {
   super.mouseDown(with: event)
   if event.clickCount >= 2 {
      ... 
   }
}

That works well however I don't know how to pass this event to my ViewController. The ViewController is already implementing the NSOutlineViewDelegate protocol.

I guess that the solution is not far away but somehow I am stuck.

回答1:

UPDATED Although you can set up NSGestureRecognizer for single click and NSClickGestureRecognizer for double clicks in OSX, You should probably be using the doubleAction property of the NSOutlineView directly.

Here's an example of how to set it up

This comes from a another of the Wenderlich tutorials, and there is a good discussion on SO already