问题描述
我以编程方式创建了我的 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 方法不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!