collectionView:didSelectItemAtIndexPath does not get called on tap

2.7k views Asked by At

I have a UICollectionViewController and this collection’s cells have a subview -let’s say A- with same frame as cell bounds.

The problem is when i tap on these cells, collectionView:didSelectItemAtIndexPath does not get called. I also set A’s exclusiveTouch to YES but still nothing. And also when i change A’s frame to a smaller size, tapping remaining area fires collectionView:didSelectItemAtIndexPath, no problem.

What should i actually do at that point to make this collectionView delegate get called where A’s bounds is same with cell.

I would appreciate any comments.

5

There are 5 answers

1
Pradumna Patil On

Check your method is it - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath or - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath

It happens sometimes.

Have you disabled user interaction property of your cell check this once.

4
dopcn On

Setting exclusiveTouch to YES causes the receiver to block the delivery of touch events to other views in the same window. So leave it to NO

else if your subview is a UIImageView set userInteractionEnabled to YES

else if your subview is UIButton or other UIControl subclass which will capture tap gesture you need change it to plain UIView subclass

3
Mikael On

the method should be override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) and be sure that :

  • the cell itself has user Interaction Enable checked(in your storyboard)
  • all children of this cell have also user Interaction Enable checked

You can find this checkbox in the Attribute inspector.

0
Declan McKenna On

I'm adding my stupidity answer just in case it helps someone else. In your viewcontroller remember to set the collectionview's delegate

collectionView.delegate = self
1
Muhsin Zahid Ugur On

If I understand your question correctly, you have UICollectionViewCells with subviews in it. In order to fire didSelectItemAtIndexPath for touches on subviews, you need to disable "User Interaction Enabled" in the interface builder. I have a UIButton as a subview in my collection view cell and this is what worked for me.