UICollectionView only calling didSelectItemAtIndexPath if user double taps, will not call when user single taps

前端 未结 14 1644
名媛妹妹
名媛妹妹 2020-12-07 18:58

I have a UICollectionView which is about the size of the screen. The UICollectionViewCells that it displays are the same size as the collectionView. Each cell has a UIImage

相关标签:
14条回答
  • 2020-12-07 19:05

    I was just having the same problem and it turned out that there was a UITapGestureRecognizer on the UIView containing the UICollectionView and it was responding instead.

    That explains why didSelectItemAtIndexPath works only if the user taps with two fingers or long presses with one finger because that doesn't trigger the UITapGestureRecognizer.

    So, check all the UITapGestureRecognizer you got there, not necessarily on the UICollectionView directly but it could be on any UIView containing it.

    0 讨论(0)
  • 2020-12-07 19:05

    If you use only didselect:

    self.collectionView.allowsMultipleSelection = false
    

    Or delete that line.

    0 讨论(0)
  • 2020-12-07 19:07

    I just had the same problem...I was overriding touchesBegan in the CollectionCell view and this caused the didSelectItemAtIndexPath to not fire when I touched the cell. Removed the override and all worked.

    0 讨论(0)
  • 2020-12-07 19:09

    Try removing all of your UIGestures from the view then test to see if the UICollectionView Cells are able to be interacted with normally.

    In my case, I had to remove the lines:

    let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
        self.view.addGestureRecognizer(tap)
    
    0 讨论(0)
  • 2020-12-07 19:12

    I'm happened to stumble upon this problem, and it frustrated me one long day until I found this You just need to uncheck "User Interaction Enabled" when I selected the Cell on the top left inside the CollectionView in Storyboard. and problem solved

    0 讨论(0)
  • 2020-12-07 19:12

    Remember to add UICollectionViewDataSource, UICollectionViewDelegate to the class

    0 讨论(0)
提交回复
热议问题