【发布时间】:2019-11-21 23:57:57
【问题描述】:
我有 2 个不同数据的数组
var array : [String] = ["getMeals", "getMeasure", "getWorkouts"]
var array2 : [String] = ["getStep", "getStep", "getStep"]
我正在尝试从数组中检索图像,但在不同的集合单元格中。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.section == 0{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WorkoutCollectionCell", for: indexPath) as! WorkoutCollectionCell
cell.collectionImage.image = UIImage(named: array[indexPath.row])
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WorkoutCollectionCell", for: indexPath) as! WorkoutCollectionCell
cell.collectionImage.image = UIImage(named: array2[indexPath.row])
return cell
}
}
我需要创建另一个 UICollectionViewCell 还是可以使用当前单元格?
【问题讨论】:
-
简短的回答是肯定的,首先将单元格出列,根据您想要的任何条件分配内容,然后返回单元格。
标签: ios swift uitableview uicollectionview uicollectionviewcell