Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift didSelectItemAt indexPath:由于某些原因无法在UICollectionview中工作_Swift_Uicollectionview - Fatal编程技术网

Swift didSelectItemAt indexPath:由于某些原因无法在UICollectionview中工作

Swift didSelectItemAt indexPath:由于某些原因无法在UICollectionview中工作,swift,uicollectionview,Swift,Uicollectionview,这是我的collectionView代码。除了在collectionView中单击某个项目时,“didSelectItemAt”功能不起作用(未执行打印语句),其他功能都工作正常。我不希望你知道为什么,但你能告诉我,我可以检查什么使选择功能运行 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { le

这是我的collectionView代码。除了在collectionView中单击某个项目时,“didSelectItemAt”功能不起作用(未执行打印语句),其他功能都工作正常。我不希望你知道为什么,但你能告诉我,我可以检查什么使选择功能运行

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as! CollectionViewCell
    let key = imageArray[indexPath.row]
    cell.displayContent(image: key)  ///function in CollectionViewCell
    return cell
}


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    print("in here\(indexPath.row)")
}

我有一个类似的问题,并意识到我遗漏了以下内容:

self.collectionView.delegate = self

我以编程方式构建UI,希望这对您也有帮助。

我遇到了类似的问题,并意识到我缺少以下内容:

self.collectionView.delegate = self

我以编程方式构建UI,希望这对您也有帮助。

是否设置了集合视图的委托?您的手机是否可能有窃取触摸事件的视图?是否启用了选择和用户交互,并且手机内没有视图捕捉您的手势(例如按钮)?是缺少的代理,谢谢!请设置为Answer我认为您还应该使用indexPath.Item是否设置了集合视图的委托?您的手机是否可能有窃取触摸事件的视图?是否启用了选择和用户交互,并且手机内没有视图捕捉您的手势(例如按钮)?是缺少的代理,谢谢!请设置为answer我认为您还应该使用indexPath.item