2

I would like to implement an action by double clicking an item within a NSCollectionView. When using the mouseDownevent in the NSCollectionViewItem no collection view delegate method is fired anymore nor does the items property isSelected work:

the mouseDown event in the NSCollectionViewItem.swift:

override func mouseDown(with event: NSEvent) {

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

How do I need to handle click events on CollectionViewItems and CollectionView delegate methods at the same time?

Other than NSTableview or NSOutlineView there is no implemented doubleAction method for NSCollectionView. Which is sad.

Thanks!

JFS
  • 2,992
  • 3
  • 37
  • 48
  • Possible duplicate of [How to catching doubleClick events from NSOutlineView in ViewController?](http://stackoverflow.com/questions/41989426/how-to-catching-doubleclick-events-from-nsoutlineview-in-viewcontroller) – Willeke Feb 20 '17 at 16:30
  • @Willeke, no duplicate answer. Unfortunately, there is no `doubleAction` method in `NSCollectionView` integrated. – JFS Feb 20 '17 at 17:52
  • 1
    Sorry, I mixed `NSCollectionView` and `NSOutlineView` up (again). If you don't handle single clicks yourself, call `super.mouseDown(with: event)`. – Willeke Feb 21 '17 at 11:17

1 Answers1

0

If you override mouseDown(with event: NSEvent), then remember to call super.mouseDown(with: event) in it; otherwise, your collectionView delegate methods won't be called.

I'm answering this not to steal @Willeke solution in the comment above, but only because I don't want his comment (perfectly on point) to be missed by someone else! If Willeke wants to answer, I'll delete this.

cdf1982
  • 764
  • 1
  • 18
  • 34