Les*_*ter 3 ios uicollectionview swift
我将集合视图放入表格视图单元格中,并使其可以显示在单元格上,但是当我想选择集合单元格(更改颜色或打印单元格编号)时,选择功能不起作用,我需要多次点击单元格以使其被选中。为什么单元格检测所选项目慢?什么代码会影响要选择的单元格?
这是选择集合单元格的代码
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]
}
}
Run Code Online (Sandbox Code Playgroud)
项目 zip 链接:https : //www.dropbox.com/s/y10dgp3q61pi5n1/Finnciti.zip?dl=0
AddViewCell.swift 上的问题
| 归档时间: |
|
| 查看次数: |
1427 次 |
| 最近记录: |