【发布时间】:2022-02-22 08:43:42
【问题描述】:
我有一个这样的 CollectionView 数据源;
struct HomeSection {
var title: String?
var cellType: [HomeCellType]
init(title: String?, cellType: [HomeCellType]) {
self.title = title
self.cellType = cellType
}
}
struct HomeModel {
static let model = [
HomeSection(title: "Stock", cellType: [.inStock(text: "Show In-Stock only")]),
HomeSection(title: "Product", cellType: [.walls(text: "Walls"), .floors(text: "Floors"), .fabrics(text: "Fabrics")]),
HomeSection(title: "Similarity", cellType: [.similarity]),
HomeSection(title: "Upload", cellType: [.camera, .photo])
]
}
我想限制
HomeSection(title: "Product", cellType: [.walls(text: "Walls"), .floors(text: "Floors"), .fabrics(text: "Fabrics")])
能够选择一个单元格。我已经完成了override var is Selected 方法。但是,一旦我在另一个部分中选择了另一个单元格,它就会取消选择该部分中的单元格。我将如何在didSelectItemForIndexPath 中处理这个问题?
更新
我这样称呼我的数据源;
private let dataSource = HomeViewDataSource(sections: HomeModel.model)
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
switch dataSource.sections[indexPath.section].cellType[indexPath.item] {
}
}
【问题讨论】:
标签: swift model uicollectionview uicollectionviewcell