I have a UICollectionView with multiple cells inside of it. Each cell has one label which contains the below data.
What I would like to do is for the labels text that aren't "A" or "B", I would like the value to be an Int value based on the order of the cell.
Example
Cells Label text at the moment:
A, A, 3, B, 5, A, B
What I would like:
A, A, 1, B, 2, A, B
Any help is greatly appreciated, many thanks!!
Code:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! DataCell
let integerArray = [Int](1...10)
let sortedCellData = cellData.sorted { $0.key < $1.key}
if String(Array(sortedCellData)[indexPath.row].value) == "A" {
cell.valueLabel.text = "A"
} else if String(Array(sortedCellData)[indexPath.row].value) == "B" {
cell.valueLabel.text = "B"
} else {
cell.valueLabel.text = String(integerArray[indexPath.row])
}
return cell
}
}
Aucun commentaire:
Enregistrer un commentaire