为什么 UICollectionView didSelect 方法不起作用? [英] Why UICollectionView didSelect method does not work?

查看:45
本文介绍了为什么 UICollectionView didSelect 方法不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式创建了我的 UICollectionView,在这种情况下,我的 didSelectItemAtIndexPath 方法根本没有调用.

I've created my UICollectionView programmatically and in this case my didSelectItemAtIndexPath method does not call at all.

let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: CGRectGetWidth(self.view.frame), height: 360), collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.userInteractionEnabled = true

那么,有什么问题吗?为什么当我点击单元格时我没有得到我的回应?

So, what is a problem? Why when I tap on the cells I do not get my response?

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    print("Selected Cell: \(indexPath.row)")
}

推荐答案

我知道这可能晚了,但为了功能目的,CollectionView[didSelectItem] 不响应触摸可能是由于您还启用了 addGestureRecognizer,因此请检查您是否在 CollectionView 上设置了手势识别器,就像 collectionView?.addGestureRecognizer(tapGestRecognizer)

i Know this may be late, but for the sakes of feature purpose, CollectionView[didSelectItem] not responding to touch could be as a result of you also enalbing addGestureRecognizer so check if you have set a gesture recognizer on your CollectionView like so collectionView?.addGestureRecognizer(tapGestRecognizer)

这篇关于为什么 UICollectionView didSelect 方法不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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