在我的集合视图中,单元格类必须具有完全不同的外观,以用于数组中的不同类型的数据.
我正在寻找一种方法来创建多个单元格,并根据输入数据选择不同的单元格,例如:
internal func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell1 = collectionView.dequeueReusableCell.. as! kind1
let cell2 = collectionView.dequeueReusableCell.. as! kind2
// here choose a different one for each kind of data
return cell1
}
Run Code Online (Sandbox Code Playgroud)
我试图了解是否:
你需要做这样的事情
internal func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (data.kind == kind1) {
let cell1 = collectionView.dequeueReusableCell.. as! kind1
return cell1
} else {
let cell2 = collectionView.dequeueReusableCell.. as! kind2
return cell2
}
}
Run Code Online (Sandbox Code Playgroud)
通过检查数据的类型,您可以确定单元格.
| 归档时间: |
|
| 查看次数: |
5909 次 |
| 最近记录: |