gpt4 book ai didi

ios - Collection View 单元格在 swift 中缓慢检测所选项目

转载 作者:搜寻专家 更新时间:2023-10-31 22:01:25 26 4
gpt4 key购买 nike

我将 Collection View 放入表格 View 单元格中,并使其可以显示在单元格上,但是当我想选择集合单元格(更改颜色或打印单元格编号)时,选择功能不起作用,我需要多次点击单元格才能选中它。为什么单元格检测到选定的项目很慢?什么代码会影响要选择的单元格?

这是选择集合单元格的代码

override func awakeFromNib() {
super.awakeFromNib()

let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
let width = UIScreen.main.bounds.width
layout.scrollDirection = .vertical
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
layout.itemSize = CGSize(width: width/5, height: width/4)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
collectionView?.collectionViewLayout = layout
collectionView?.delaysContentTouches = false

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CategoryCollectionViewCell
cell.cateImg.image = imageName[indexPath.row]
cell.cateLabel.text! = nameArray[indexPath.row]
return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) as? CategoryCollectionViewCell {
cell.cateImg.image = imageName2[indexPath.row]
print("collectionViewCell selected \(indexPath)")
}
}

func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) as? CategoryCollectionViewCell {
cell.cateImg.image = imageName[indexPath.row]
}
}

enter image description here

项目压缩链接: https://www.dropbox.com/s/y10dgp3q61pi5n1/Finnciti.zip?dl=0

AddViewCell.swift 问题

最佳答案

尝试在 Collection View 属性中取消选中此复选标记

enter image description here

关于ios - Collection View 单元格在 swift 中缓慢检测所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47094345/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com