【发布时间】:2014-12-28 06:57:14
【问题描述】:
我正在使用水平集合视图来滚动日期。集合视图包含 30 个单元格。如果我选择第一个单元格,以指示选择,单元格背景颜色已从默认颜色红色更改为棕色。然后,如果我选择另一个单元格,则选定的单元格颜色已从红色变为棕色。但第一个单元格 BGColor 保持不变(棕色)。如何通过单击其他单元格更改为默认颜色?
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath
indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell",
forIndexPath: indexPath) as myViewCell
cell.date_label.text = arr_date[indexPath.item]
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath
indexPath: NSIndexPath) {
var cell = collectionView.cellForItemAtIndexPath(indexPath) as myViewCell
if(cell.selected)
{
cell.backgroundColor = UIColor.brownColor()
}
else
{
cell.backgroundColor = UIColor.redColor()
}
}
【问题讨论】:
标签: swift ios8 uicollectionview