UICollectionView委托的tap方法没有被调用 [英] UICollectionView delegate's tap method not getting called
问题描述
我有一个集合视图,数据源委托效果很好,但 UICollectionViewDelegate
:
I have a collection view, the datasource delegate works well, but UICollectionViewDelegate
:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didselect");
}
没有被调用,虽然我设置了委托(就像我对数据源做的那样)并且它工作了)
我必须提到我的单元格是从一个nib加载并连接到 UICollectionViewCell
的子类,无论如何单元格不响应我的触摸。我在我的单元格中的 UIImageView
中启用了用户交互。
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.
还:
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"this is caled");
return YES;
}
未被调用!
正如我所提到的那样:
[self.collectionView setDelegate:self];
当然
<UICollectionViewDelegate>
我也没有任何 touchBegan
覆盖..
also I don't have any touchBegan
override ..
更新:
WEIRD!如果我长按,它只会被调用!我怎么能解决这个问题,我将delayedContentTouches设置为NO加上我没有实现任何手势识别器。
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.
请帮助。谢谢。
推荐答案
看起来某处有一个 UITapGestureRecognizer
视图层次结构。默认情况下, UITapGestureRecognizer
会消耗他们收到的触摸,这意味着它不会传递给层次结构中它下面的视图。您需要找到流氓点击手势并添加此行
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 line
tapGestureRecognizer.cancelsTouchesInView = NO;
这会使它在层次结构中传递给它下面的视图,并希望能解决你的问题。
This will make it pass touches to views below it in the hierarchy, and hopefully solve your problem.
这篇关于UICollectionView委托的tap方法没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!