2
votes

I'm using an UICollectionView added on top of a view with a single tap gesture recogniser. The CollectionView makes use of custom cells without any subviews. The delegate's method

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

is only called when selecting the cell with two instead of one finger or when doing a LONG press using a single finger.

I'm not accidentally overriding

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath.

I read through all similar questions which were all solved by removing some kind of view or gesture recogniser.

Any ideas what's wrong here?

3
I'm feeling uder water rocks, can you share a simple project with it behaviour?Bimawa
post your for selection pleaseDevang Tandel
did you tried without didDeselectItemAtIndexPath ?Jack
self.collectionView.allowsMultipleSelection = false try thisSivajee Battina

3 Answers

5
votes

The solution: The collection view was added on top of a view containing a single-tap gesture recogniser. This some how caused this behaviour. I removed the recogniser from the collection views parent view and it works.

Feel free to explain why this is expected behaviour. I would have argued that the top most view (CollectionView) handles the touches before they are passed to the view behind.

2
votes

An alternative to removing the gesture completely is to set it so that it doesn't cancel touches in view.

UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(someSelector)];
tapRecognizer.cancelsTouchesInView = NO;
tapRecognizer.delaysTouchesBegan = NO;
tapRecognizer.delaysTouchesEnded = NO;
[self.view addGestureRecognizer:tapRecognizer];
0
votes

Based on Christoph solution; I've come up with this code, which is removing all the gesture recognisers in my parent view.

for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
    [self.view removeGestureRecognizer:recognizer];
}