【发布时间】:2015-05-01 06:09:09
【问题描述】:
我在收藏视图中的选定项目有问题。
选定的项目将背景颜色更改为蓝色,但似乎可重复使用的单元格也受到了影响。
我的代码如下所示:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
var cell = collectionView.cellForItemAtIndexPath(indexPath) as UICollectionViewCell?
cell?.contentView.backgroundColor = UIColor.blueColor()
func collectionView(collectionView: UICollectionView, didDeslectItemAtIndexPath indexPath: NSIndexPath) {
var cell = collectionView.cellForItemAtIndexPath(indexPath) as UICollectionViewCell?
cell?.contentView.backgroundColor = UIColor.blackColor()
}
func collectionView(collectionView: UIControllerView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: boxCell = collectionView.dequeueReusableCellWithReuseIdentifier("demoCell", forIndexPath: indexPath) as boxCell
cell.cellTitle.text = name[indexPath.row]
}
当我运行应用程序时,选择有效,选择另一个单元格,取消选择其他选定的单元格,但是当我滚动时,可重复使用的单元格也变成蓝色。
我使用的是水平滚动方向,每行只有 1 行和 4 个单元格。
我哪里做错了?其他人遇到过这个问题吗?
【问题讨论】:
标签: ios swift collectionview