【发布时间】:2018-12-31 10:12:48
【问题描述】:
我从我的 firebase 数据库中获取一个用于下载图像的 url,并且在主线程中的 cell.articleImage.image = UIImage(data: data) 上收到此错误,它没有崩溃但不会返回图片,有谁知道哪里出了问题?
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
DispatchQueue.global().async {
let v = UIView(frame: .zero)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "articleCell") as? articlesCell else {
return UITableViewCell()}
let article = articleArray[indexPath.row]
let url = URL(string: article.imageURL)!
DispatchQueue.global().async {
do{
let data = try Data(contentsOf: url)
DispatchQueue.global().sync {
cell.articleImage.image = UIImage(data: data)
}
} catch {
}
}
// cell.articleImage.sd_setImage(with: url, placeholderImage: UIImage(named: "issaimage"))
cell.configureCell(title: article.ArticleTitle, author: article.author, date: article.date)
return cell
}
【问题讨论】:
标签: ios swift firebase uiimageview uiimage