作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我将 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]
}
}
项目压缩链接: https://www.dropbox.com/s/y10dgp3q61pi5n1/Finnciti.zip?dl=0
AddViewCell.swift 问题
最佳答案
关于ios - Collection View 单元格在 swift 中缓慢检测所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47094345/
我是一名优秀的程序员,十分优秀!