UIImage, prepareForReuse and multiple reload data

So you are working on a UICollectionView and you have to call “reloadData()” a few times in a row because you have data coming in. I know it would be better to insert items or at least reload the section but sometimes for good or bad reasons, like custom layout manager and iOS 9, it’s not always possible. And it’s not the point here anyway.  The point is I recently had a problem with my UIImageView flashing like crazy overtime I call “reloadData()” .  I found out in your “prepareForReuse()” implementation, rather than setting you imageView.image = nil you’re better off doing imageView.hidden = true and unhide it later when you need to set it again in “cellForItemAtIndexPath”.

MyCell.swift

Not much but I thought it could interest some of you guys. Cheers !

Edit: It might not be the best solution after all. It behave poorly in bad / slow network conditions. 

Leave a Reply

Your email address will not be published. Required fields are marked *