swift - 当我点击单元格时,collectionView 内的视图没有隐藏
问题描述
我想根据特定单元格上的点击隐藏与 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
}
解决方案
通过更新
let cell=collectionView.dequeueReusableCell(withReuseIdentifier:reuseIdentifier, for: indexPath) 解决了它!集合视图单元
在 didSelectItemAt 中
让 cell = collectionView.cellForItem(at: indexPath) as!集合视图单元
并添加带有类的 UICollectionViewDelegate。
推荐阅读
- reactjs - 从反应原生的堆栈导航器中删除屏幕
- ios - iOS 上的 Flutter 插件抛出错误“线程 1:EXC_BAD_ACCESS”
- tensorflow - 使用 Tensorflow 服务为数百个模型提供服务
- javascript - 从给定数组中查找单击元素的最近祖先
- python - 删除列表 Pandas Dataframe 列的倒数第二个元素
- c++ - 嵌套容器的自定义分配器
- flutter - 如何使用 dart null-safety 对可能包含空值的列表进行排序
- angular - Angular rxjs Subject,组件没有收到Subject发送的数据
- opencv - 我的 OpenCV 4.2.0 源代码中的 CMAKE 找不到我的机器中安装的任何 cuDNN
- logging - 已解决:如何在运行时重新路由 Arduino/ESP 串行输出?