UITableViewCell图像未加载
问题描述:
我想从firebase存储中下载图像并将其加载到tableview中,但它不起作用。 我的downloadUrl
是正确的,没有错误。UITableViewCell图像未加载
URLSession.shared.dataTask(with: downloadURL) { (data, response, error) in
if error != nil {
print(error?.localizedDescription)
return
}
DispatchQueue.main.async {
if let downloadedImage = UIImage(data: data!) {
cell.imageView?.image = downloadedImage
}
}
}
答
为什么不直接使用Firebase存储的built in download mechanisms这个?
let httpsReference = FIRStorage.storage().referenceForURL('https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg') // your download URL
httpsReference.dataWithMaxSize(1 * 1024 * 1024) { (data, error) -> Void in
if (error != nil) {
// Uh-oh, an error occurred!
} else {
// Data for "images/stars.jpg" is returned
let starsImage: UIImage! = UIImage(data: data!)
cell.imageView.image = starsImage // by default, callbacks are raised on the main thread so this will work
}
}
什么不工作?你有错误吗? 您是否尝试过使用断点来查看过程中失败的内容?单元格是否为空?图像是否为空?你能否详细说明你所知道的*是否正确以及你认为问题开始的地方。因此,我们可以开始工作了:) –
单元格不为空,图像不是空的,我没有错误。我想在我的tableview中显示图像,但图像不显示。 –
尝试在派发或其他事物中打印图像,并查看是否可以打印它。 – Dravidian