2

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Oliver Koehler
  • 711
  • 2
  • 8
  • 24

1 Answers1

2

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 enter image description here

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

Community
  • 1
  • 1
Russell
  • 5,436
  • 2
  • 19
  • 27
  • You can use the tap gesture in Cocoa? I didn't know that. – El Tomato Feb 01 '17 at 22:47
  • sorry - I missed that we're talking OSX, but you can use `NSGestureRecognizer` rather than `UIGestureRecognizer`. Have a look at https://developer.apple.com/reference/appkit/nsgesturerecognizer – Russell Feb 01 '17 at 22:50
  • @Russel, thanks for the answer. I am away from my Mac but if I have understood you correctly I need to * Instantiate a NSClickGestureRecognizer(target: myViewController, action: handleGesture) * Add the gestureRecognizer to my NSOutlineView * Implement a handleGesture method in myViewController – Oliver Koehler Feb 02 '17 at 06:58
  • @Russell: Aarrgh! The Ray Wenderlich Tutorials are always my first place to look. Must have missed out this one. Thanks for mentioning :-) – Oliver Koehler Feb 02 '17 at 08:35