如何在ViewController中从NSOutlineView捕获doubleClick事件? [英] How to catching doubleClick events from NSOutlineView in ViewController?

查看:96
本文介绍了如何在ViewController中从NSOutlineView捕获doubleClick事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从NSOutlineView捕获doubleClick事件,以将其传递给ViewController.我的想法是捕获doubleClick事件并从我的OutlineView中获取选定的行 到目前为止,我所做的是将NSOutlineView子类化以覆盖mouseDown

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 {
      ... 
   }
}

那很好,但是我不知道如何将这个事件传递给我的ViewController. ViewController已经在实现NSOutlineViewDelegate协议.

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.

推荐答案

更新 尽管可以在OSX中为单击设置NSGestureRecognizer,为双击设置NSClickGestureRecognizer,但是您可能应该直接使用NSOutlineViewdoubleAction属性.

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

这来自另一个 Wenderlich教程,并且有关于已经如此的

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

这篇关于如何在ViewController中从NSOutlineView捕获doubleClick事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆