PinterestLayout icon indicating copy to clipboard operation
PinterestLayout copied to clipboard

didSelectItemAt not called in CustomCollectionVC ?

Open ghost opened this issue 6 years ago • 2 comments

Hello,

I noticed that function override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { } Is not called when using CustomCollectionVC from example, it works fine for MyPinterestVC.

https://github.com/karek314/PinterestLayout/commit/4e2994664103319d8c4503e567b0152d13b71a9b https://github.com/karek314/PinterestLayout/commit/66c73eb8f9564512789c0333095a64d57139a9c3

Cheers

ghost avatar Jul 09 '19 15:07 ghost

I noticed that ImageView of collectionview prototype has interactions disabled in interface builder, however it does not fix didSelectItemAt method. Solution for me was to add following code along with enabling interactions. Not perfect but it works just fine.

Viewdidload

let TapDetector: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(Tapped(_:)))
        TapDetector.numberOfTapsRequired = 1
        TapDetector.numberOfTouchesRequired = 1
        collectionView?.addGestureRecognizer(TapDetector)
    }
@objc func Tapped(_ tap: UITapGestureRecognizer){
        let point: CGPoint = tap.location(in: collectionView)
        let indexPath: IndexPath = (collectionView?.indexPathForItem(at: point))!
        let ArrayIndex = indexPath.row
        NSLog("Tapped: \(ArrayIndex)")
    }

ghost avatar Jul 11 '19 10:07 ghost

This is also important fix for this library https://github.com/MagicLab-team/PinterestLayout/pull/4

ghost avatar Jul 11 '19 10:07 ghost