Home Table view images not loading with or without DispatchQueue
Reply: 1

Table view images not loading with or without DispatchQueue

Nate
1#
Nate Published in 2018-01-12 04:08:45Z

I'm using the SDWebImage library to load images into my table cells as imageView. I'm having a similar issue to this post; my tableView loads but without the images. When I click on a cell and then go back to the main page, the images have finally loaded. But I want the images to load without having to do that (without any interaction).

However, removing the DispacheQueue.main.async doesn't fix the issue; the images still aren't loaded. I read that cell.setNeedsLayout() and cell.layoutIfNeeded() were supposed to help fix this, but they didn't.

myURLss is my array of URLs, by the way

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell")

        DispatchQueue.main.async {
            cell?.imageView?.sd_setImage(with: self.myURLss[indexPath.row])
            cell?.setNeedsLayout()
        }

    return cell!

}
iOS Geek
2#
iOS Geek Reply to 2018-01-12 05:13:48Z

I tried using SDWebImage Check Project at Link -

https://drive.google.com/open?id=1BQ_3fFvD04BnGa5uRqbAtU4DWGn_Pzpq

I created My custom cell class in which imageView is Connected and updating it in cellFOrRowAt of TableView

class CustomCell: UITableViewCell {

    //My ImageView
    @IBOutlet weak var myImageView: UIImageView!

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

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

My TableView CellForRowAt

 //Setting cells data
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {

        let cell = self.myTableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! CustomCell

        DispatchQueue.main.async
            {
            cell.myImageView.sd_setImage(with: self.myURLss[indexPath.row], completed: nil)
        }

        return cell
    }

Also as you are using SDWebImage Library they provide set of options To us

if still image in your code does not show try using below line

cell.myImageView.sd_setImage(with: self.myURLss[indexPath.row], placeholderImage: #imageLiteral(resourceName: "malee"), options: .continueInBackground, completed: nil)

Hope It helps

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.325251 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO