D
D
Dmitry Chizhov2016-03-25 10:47:13
iOS
Dmitry Chizhov, 2016-03-25 10:47:13

Why do images jump from cell to cell in CollectionView?

Happy Friday everyone!
I continue my studies of swift. Faced with an incomprehensible situation that pictures are displayed in the CollectionView, and so these pictures are replaced by others when loading, then they are replaced by the necessary ones. When scrolling, cells with previously loaded pictures are also created. And in the same order in which they were created earlier. Those. just duplicates 1, 2, 3, etc. Moreover, such a trick is repeated if you scroll up, then back down. When you continue scrolling (recreating the cell), the process of loading the picture starts and the necessary pictures are inserted.
here is what i do:

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

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

        let filename = "http://site.ru/img.jpg"
        let URL = NSURL(string: filename)!
        cell.image.af_setImageWithURL(URL)

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shannon, 2016-03-31
@Shannon

Need placeholderImage
For example, https://github.com/rs/SDWebImage would be like this

cell.image.sd_setImageWithURL(NSURL(string: imgUrl)
     , placeholderImage: UIImage(named:"void-img"))

AlamofireImage also has something similar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question