SDWebImage 不起作用 [英] SDWebImage doesn't work
本文介绍了SDWebImage 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做错了什么?一切都在运行,但我没有得到图像,帮助!谢谢!
What am I doing wrong? Everything runs but I don't get the Images, help! Thanks!
import UIKit
import Firebase
import FirebaseDatabase
import SDWebImage
struct postStruct {
let title : String!
let downloadURL : String!
}
class ZeroHomeViewController: UITableViewController {
var posts = [postStruct]()
override func viewDidLoad() {
super.viewDidLoad()
let ref = Database.database().reference().child("Posts")
ref.observeSingleEvent(of: .value, with: { snapshot in
print(snapshot.childrenCount)
for rest in snapshot.children.allObjects as! [DataSnapshot] {
guard let value = rest.value as? Dictionary<String,Any> else { continue }
guard let title = value["Title"] as? String else { continue }
guard let downloadURL = value["Download URL"] as? String else { continue }
let post = postStruct(title: title, downloadURL: downloadURL)
self.posts.append(post)
}
self.posts = self.posts.reversed(); self.tableView.reloadData()
})
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
let imageView = cell?.viewWithTag(200) as! UIImageView
imageView.sd_setImage(with: URL(string: "downloadUrl"), placeholderImage: UIImage(named: "placeholder.png"))
let label1 = cell?.viewWithTag(1) as! UILabel
label1.text = posts[indexPath.row].title
return cell!
}
}
推荐答案
其次
替换这一行imageView.sd_setImage(with: URL(string: "downloadUrl"), placeholderImage: UIImage(named: "placeholder.png"))
Replace this line imageView.sd_setImage(with: URL(string: "downloadUrl"), placeholderImage: UIImage(named: "placeholder.png"))
有了这个
imageView.sd_setImage(with: URL(string: "www.domain.com/url"), placeholderImage: UIImage(named: "placeholder.png"))
imageView.sd_setImage(with: URL(string: "www.domain.com/url"), placeholderImage: UIImage(named: "placeholder.png"))
确保您将网址编辑为您想要的图片
Make sure your edit the url to the image you want
这篇关于SDWebImage 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文