lundi 29 juin 2015

Trouble understanding resuming cells in collection views


I'm following a site to help learn swift and I'm getting confused about this part right here. Basically we added the if cell.imageview.image == nil statement so hat when the collection view loads and you scroll the image doesn't reload the filters. What I don't understand is if you scroll down a cell is reused for the bottom row, now why if I scroll back up doesn't it have to reload the filter? is that data saved somewhere so when I scroll up the properties don't have to repopulate? and If thats the case why would I have to use that if statement at all?

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
}


Aucun commentaire:

Enregistrer un commentaire