首页 > 解决方案 > collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath 没有执行

问题描述

这是我的 collectionViewCell 图像。

细胞图像

我在collectionView里面tableViewCell,里面有一个按钮collectionViewCell,可以按我的意愿完美工作。但令我困扰的是该函数didSelectItemAt 没有被调用。

我试过了

mycollectionview.isUserInteractionEnabled = true
mycollectionview.allowsSelection = true

但仍然无法正常工作。当我在某处阅读时,里面的按钮collectionViewCell是它背后的原因。如果是这样,我该如何解决这个问题。

标签: iosswiftcollectionview

解决方案


请确认您已将委托设置UICollectionView为您的 ViewController 而不是TableViewCell. 如果您已将 Delegate 设置为UITableViewCell,那么您didSelectItemAt将在TableViewCell's类内被调用


推荐阅读