OGeek|极客世界-中国程序员成长平台

标题: ios - Swift 2,滚动后的 UiCollectionview - 更改单元格数据 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 16:47
标题: ios - Swift 2,滚动后的 UiCollectionview - 更改单元格数据

对于单元格,我只是从数组中输入信息:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

            let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! ImagesCollectionViewCell

            if cell.dateLabel.text == "" {
                cell.dateLabel.text = imagesDatas[indexPath.row].datesStr
                cell.image.image = imagesDatas[indexPath.row].images
            }
            return cell
        }

为了数组,我在 DidAppear 中生成数据。只有一次。 但是当我滚动 collectionView - 单元格更改数据时,例如:

1 个单元格 - 图片A

2 单元格 - 图片B

然后滚动,在collectionview中会看到:

1 个单元格 - 图片B

2 单元格 - 图片A

然后滚动,在collectionview中又会看到:

1 个单元格 - 图片A

2 单元格 - 图片B

无法理解这里发生了什么......



Best Answer-推荐答案


override func prepareForReuse() {
    super.prepareForReuse()

      cell.dateLabel.text = nil
        cell.image.image = nil

}

关于ios - Swift 2,滚动后的 UiCollectionview - 更改单元格数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37963558/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4