1
我想更改所選單元格的單元格背景色,但任何時候我選擇一個單元格,它都會更改所選單元格和另一個隨機單元格的背景顏色。什麼可能是錯的?UICollectionViewCell更改多個單元格的背景顏色
這裏是我的代碼:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! UICollectionViewCell
cell.contentView.backgroundColor = UIColor.orangeColor()
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
let cell = colorCollection.cellForItemAtIndexPath(indexPath)
cell?.backgroundColor = UIColor.blackColor()
}