我想根据特定单元格上的点击隐藏与collectionView单元格相连的底视图。我已经尝试在“ didSelectItemAt”函数上执行此操作,但是它不起作用。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CollectionViewCell
cell.bottomView.isHidden = true
}
internal func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView.frame.width, height: collectionView.frame.height)
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.lableArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CollectionViewCell
let item = lableArray[indexPath.row]
cell.imageView.backgroundColor = UIColor.randomColor()
cell.lable.text = item
return cell
}
答案 0 :(得分:0)
通过更新解决了
让cell = collectionView.dequeueReusableCell(withReuseIdentifier:reuseIdentifier,for:indexPath)为! CollectionViewCell
在didSelectItemAt中与
让cell = collectionView.cellForItem(at:indexPath)as! CollectionViewCell
并添加带有类的UICollectionViewDelegate。