[ad_1]
The issue is that I do not know easy methods to refresh photographs loaded asynchronously from url with SDWebImage.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let merchandise = objects[indexPath.row]
if let url = URL(string: merchandise.stringUrl) {
let placeholderImage = UIImage(named: "noPhoto.png")
itemImage.sd_setImage(with: url, placeholderImage: placeholderImage)
}
cell.imageView?.picture = itemImage.picture
cell.textLabel?.textual content = merchandise.title
cell.detailTextLabel?.textual content = "merchandise id: (merchandise.id)"
return cell
}
The pictures will solely refresh after scrolling by means of the desk. Till then the desk solely exhibits placeHolder picture which is anticipated because it solely reloads photographs when cells are reused. I attempted to make use of the completion handler to refresh photographs when loaded utilizing tableview.reload() as proven under:
itemImage.sd_setImage(with: url, placeholderImage: placeholderImage, accomplished: {picture,error,cache,url in
if picture != nil {
DispatchQueue.most important.async {
self.tableView.reloadData()
}
}
})
This answer ends in tableView loading all the photographs in a second which is what I need nevertheless it reloads the entire desk mainly each time I attempt to scroll by means of it so it “pushes” the entire desk to the highest place immediately.
The final answer I tries is that this:
itemImage.sd_setImage(with: url, placeholderImage: placeholderImage, accomplished: {picture,error,cache,url in
if picture != nil {
DispatchQueue.most important.async {
self.tableView.reloadRows(at: [indexPath], with: .none)
}
}
})
This additionally would not and makes tableview randomly displaying and hiding photographs.
I suppose the issue is that I attempt to reload photographs in a perform that creates cells however I am unable to discover a answer to how resolve this concern. I shall be very grateful for any assist.
[ad_2]
