UICollectionView 委托的点击方法没有被调用 [英] UICollectionView delegate's tap method not getting called

查看:18
本文介绍了UICollectionView 委托的点击方法没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集合视图,数据源委托运行良好,但是 UICollectionViewDelegate:

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

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

虽然我设置了委托,但没有被调用(就像我对数据源所做的那样,它起作用了)我不得不提一下,我的单元格是从笔尖加载的,并且连接到 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;
}

没有被调用!

正如我提到的,我确实设置了:

as I mentioned I did set:

[self.collectionView setDelegate:self];

当然是

<UICollectionViewDelegate>

我也没有任何 touchBegan 覆盖 ..

also I don't have any touchBegan override ..

更新:

奇怪!只有当我长按时它才会被调用!我该如何解决这个问题,我将 delaysContentTouches 设置为 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.默认情况下,UITapGestureRecognizers 使用他们收到的触摸,这意味着它不会传递给层次结构中它下面的视图.您需要找到流氓点击手势并添加此行

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.

这篇关于UICollectionView 委托的点击方法没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆