【问题标题】:MouseDown Event prevents NSCollectionView Delegate MethodsMouseDown 事件阻止 NSCollectionView 委托方法
【发布时间】:2017-07-09 21:20:40
【问题描述】:

我想通过双击 NSCollectionView 中的项目来执行操作。在NSCollectionViewItem 中使用mouseDownevent 时,不会再触发集合视图委托方法,也不会触发items 属性isSelected

NSCollectionViewItem.swift 中的mouseDown 事件:

override func mouseDown(with event: NSEvent) {

    if event.clickCount > 1 {
        //do something
    }
}

如何同时处理CollectionViewItemsCollectionView 委托方法的点击事件?

除了NSTableviewNSOutlineView,没有为NSCollectionView 实现doubleAction 方法。这很可悲。

谢谢!

【问题讨论】:

标签: swift macos events mousedown nscollectionview


【解决方案1】:

如果你覆盖mouseDown(with event: NSEvent),那么记得在里面调用super.mouseDown(with: event);否则,您的 collectionView 委托方法将不会被调用。

我回答这个问题不是为了窃取上面评论中的@Willeke 解决方案,而只是因为我不希望其他人错过他的评论(完全正确)!如果 Willeke 想回答,我会删除它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-15
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多