UICollectionView only calling didSelectItemAtIndexPath if user double taps, will not call when user single taps
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 which is the size of the cell. The CollectionView has paging enabled so essentially it is a full screen photo slideshow that the user can swipe through.
The problem is that-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
is only being called if the user taps with two fingers on a cell or long presses with one finger and then releases. It does not seem to have the default behaviour of single tap selection. I have not made any changes to the CollectionView gesture recognizer so am having trouble finding a solution to this problem.
Solution 1:
Are you sure you're not accidentally overriding - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
? "Select" vs. "deselect" has tripped me up in the past with Xcode's code completion.
Solution 2:
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.
Solution 3:
If you have a view on the cell which obstructs the cells content view that is intractable then you will not be able to hook into the delegate callback for the cell.
You will want to disable user interaction on the obstructing view either in the NIB or in the code.
view.userInteractionEnabled = NO;