i have been using alamofire-image library to display image from url inside uicollectionview cell.
i have noticed that most of time its displays the right image but sometimes displays wrong image(most of the time previous cell image). how to overcome this problem.
func collectionView(collectionView: UICollectionView,
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell",forIndexPath: indexPath) as! myCollectionViewCell
cell.titleLabelCell.text = element[indexPath.row]["title"]
cell.generLabelCell.text = element[indexPath.row]["gener"]
let URL = NSURL(string: "\(element[indexPath.row]["banner_site_url"])" )!
cell.mImageView.af_setImageWithURL(URL)
return cell
}
You have to break the connection with any image download request that may be in progress when you reuse the cell.
You can find a good tutorial written by Todd Kramer at:
Downloading, Caching, & Decoding Images Asynchronously In Swift With Alamofire: Part 1
Note the implementation of the cell view class PhotoCollectionViewCell. It calls the member function reset, which cancels any existing request, before launching a request for the current image.
If the images are small and likely to be reused I tend to cancel the cell update rather than the retrieval.
Read the whole thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With