Sdwebimage: Wrong Image at Some Cells

Created on 20 Jul 2018  路  4Comments  路  Source: SDWebImage/SDWebImage

New Issue Checklist

Issue Info

Info | Value |
-------------------------|-------------------------------------|
Platform Name | ios
Platform Version | 11.0
SDWebImage Version | 4.4.2
Integration Method | cocoapods
Xcode Version | Xcode 9 / Xcode 10 Beta
Repro rate | ???
Repro with our demo prj | ???
Demo project link | ???

Issue Description and Steps

Hi, Im using SDWebImage pod for download and show images from json and its working well but I have a big problem with it.

Im using collectionView and when cell is loading, some cells showing wrong image. I searched it and I tried so many solutions like image = nil and sd_cancelCurrentImageLoad() in prepareForReuse func on Cell class but not working.

I could not find any solution for solve it, please help guys thanks :)

YazilarCollectionViewCell.swift

import UIKit
import SDWebImage

class YazilarCollectionViewCell: UICollectionViewCell {

    @IBOutlet weak var haberGorseli: UIImageView!
    @IBOutlet weak var yazarAvatar: UIImageView!
    @IBOutlet weak var baslik: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func prepareForReuse() {
        super.prepareForReuse()
        self.haberGorseli.image = nil
        self.haberGorseli.sd_cancelCurrentImageLoad()
    }

}

Only Cell Part in YazilarViewController.swift

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "YazilarCollectionViewCell", for: indexPath) as! YazilarCollectionViewCell

        if indexPath.row < basliklar.count{
            cell.baslik.text = basliklar[indexPath.row].html2String
            cell.yazarAvatar.sd_setImage(with: URL(string: catResim[indexPath.row]), placeholderImage: UIImage(named: "faiklogo"))
            cell.haberGorseli.sd_setImage(with: URL(string: resimLink[indexPath.row]), placeholderImage: UIImage(named: "faiklogo"))
            cell.yazarAvatar.layer.cornerRadius = cell.yazarAvatar.frame.height/2
            cell.yazarAvatar.clipsToBounds = true

            cell.layer.shadowColor = UIColor.black.cgColor
            cell.layer.shadowOpacity = 0.25
            cell.layer.shadowOffset = CGSize(width: 0, height: 5)
            cell.layer.shadowRadius = 12
            cell.layer.masksToBounds = false
        }

        return cell
    }

All 4 comments

@halilyuce add to prepareForReuse()
self.yazarAvatar.sd_cancelCurrentImageLoad()
or digg into your code for any other mistakes

@halilyuce can you provide a simple demo project where the issue is 100% reproducible?
From past experience with similar issues, it's probably a problem within your code, but let's make sure

thanks for replies guys, I changed wordpress api for images and its working now without any changes :) Maybe you know wordpress does not give you post image url directly, its giving image id and you must to call second api for get image url so its problem for this. I installed "Better REST API Featured Images" plugin for solve it and its workin well. Thanks for your effort for this amazing pod, best regards :)

Closing based on the last comment.

Was this page helpful?
0 / 5 - 0 ratings