Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView delegate's tap method not getting called

Tags:

I have a collection view, the datasource delegate works well, but UICollectionViewDelegate:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {     NSLog(@"didselect"); } 

not get called, although i set the delegate (as i did with data source and it worked) I have to mention that my cell is loaded from a nib and is connected to a subclass of UICollectionViewCell, anyway the cells do not respond to my touch. I enabled the user interaction in the UIImageView that is in my cell.

also :

-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {     NSLog(@"this is caled");     return YES; } 

is not getting called!

as I mentioned I did set:

[self.collectionView setDelegate:self]; 

and of course

<UICollectionViewDelegate> 

also I don't have any touchBegan override ..

UPDATE:

WEIRD! it only gets called if I long press! how can I fix this, I set delaysContentTouches to NO plus i don`t have any gesture recognizers implemented.

help please. thanks.

like image 746
henTdev Avatar asked Jul 17 '13 12:07

henTdev


2 Answers

It looks like there is a UITapGestureRecognizer somewhere up in the view hierarchy. By default, UITapGestureRecognizers consume the touch that they recieve, meaning that it is not passed to the views below it in the hierarchy. You need to find the rogue tap gesture and add this line

tapGestureRecognizer.cancelsTouchesInView = NO; 

This will make it pass touches to views below it in the hierarchy, and hopefully solve your problem.

like image 180
aksh1t Avatar answered Dec 04 '22 22:12

aksh1t


Looks like you've added TapGestureRecognizer somewhere and it prevents selecton of cell. Check them, that should be the problem.

like image 38
Timur Kuchkarov Avatar answered Dec 04 '22 20:12

Timur Kuchkarov