【发布时间】:2020-04-18 14:43:05
【问题描述】:
我有简单的 CollectionView,我需要将索引 1 处的背景单元格设置为绿色,启动时可以(看图片)
但是在我向下和向后滚动后,我有很多绿色单元格? 我该怎么办?
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {[enter image description here][1]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! MessageCollectionViewCell
cell.textMessageLabel.text = arrMes[indexPath.row].textMessage
cell.dataMessage.text = arrMes[indexPath.row].dataOfMessage
if indexPath.row == 1 {
cell.backgroundColor = .green
}
return cell
}
【问题讨论】:
标签: ios swift xcode indexing uicollectionview