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.
I had a similar issue with PSUICollectionView (this works on iOS5 too) and I fixed it by putting a button on my CollectionViewCell and setting the target of that button Also add tag's to know which button is pressed.
Ensure there aren't any objects setting the
userInteractionEnabled
property toNO
on theUICollectionViewController
.Similar to what other people are saying, I had this same problem and it was fixed by removing a call to
userInteractionEnabled
where the parent view was adding it as a child view controller. I was able to test this by adding aUIButton
to the cell and determining that even it couldn't receive the touch events.I was facing the same issue, that clicking on the custom UICollectionView Cell, it was not detecting the click. In my case, the problem was that in the CustomCell's Xib, the userInteraction was enabled and that's why UICollectionview's didSelectItemAtIndexPath was not getting called, instead user tap information was being sent to that particular cell for which I had no handler.
It looks like there is a
UITapGestureRecognizer
somewhere up in the view hierarchy. By default,UITapGestureRecognizer
s 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 lineThis will make it pass touches to views below it in the hierarchy, and hopefully solve your problem.
Looks like you've added TapGestureRecognizer somewhere and it prevents selecton of cell. Check them, that should be the problem.
Adding here as a reference for other people who are looking for the answer
Short Answer:
Delay the touches of default gesture recognizers associated with the tableview:
Explanation
Every tableview has gesture recognizers associated with it. Which causes the delays of touches to custom UItableView cell. Set the delaysTouchesBegan to true so that the touch can be passed to subviews quickly.
In my case it was CollectionViewController inside UItableViewCell for which collectionView:didSelectItemAtIndexPath was being called with a delay.