无法理解集合视图中的恢复单元格

Trouble understanding resuming cells in collection views

我正在关注一个帮助学习的网站 swift,我对这里的这一部分感到困惑。基本上我们添加了 if cell.imageview.image == nil 语句,所以当集合视图加载并且您滚动图像时不会重新加载过滤器。我不明白的是,如果您向下滚动,底部行会重复使用一个单元格,现在为什么如果我向上滚动,它不必重新加载过滤器?数据是否保存在某处,以便当我向上滚动时不必重新填充属性?如果是这样的话,我为什么还要使用那个 if 语句?

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

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCell", forIndexPath: indexPath) as! FilterCell

    if cell.imageView.image == nil {
        cell.imageView.image = placeholder

        let filterQueue: dispatch_queue_t = dispatch_queue_create("filter queue", nil)

        dispatch_async(filterQueue, { () -> Void in
            let filterImage = self.filteredImageFromImage(self.thisFeeditem.thumbNail, filter: self.filters[indexPath.row])

            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                cell.imageView.image = filterImage
            })
        })
    }
    return cell
}

无论向上或向下滚动,单元格都可以重复使用。您应该假设返回的单元格是不同项目的缓存版本。因此,它可能已经与另一个单元格的数据绑定,并且您希望始终将单元格与正确的项目数据重新绑定。

当一个单元格被重用时,一个已经分配的单元格对象被再次使用。为其设置的任何属性或数据都将保留。

当您向上滚动时,单元格已经设置了图像,因此它不会重新加载新的过滤图像。