【发布时间】:2019-07-07 22:18:56
【问题描述】:
我的单元格在 StoryBoard 上设置为蓝色,但即使我在用户选择单元格时更改单元格背景颜色,它们仍保持蓝色(不是红色)。我的代码有什么问题?
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "throneCell", for: indexPath) as! CharacterViewCell
let character = characters[indexPath.row]
cell.backgroundColor = UIColor.red
onBoardingService.pickCharacter(character: character)
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "throneCell", for: indexPath) as! CharacterViewCell
let character = characters[indexPath.row]
onBoardingService.removeCharacter(character: character)
}
【问题讨论】:
标签: swift colors background uicollectionview cell