我遇到了错误:
严重错误:解开Optional值时意外发现nil。
DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async {
let imageString = self.thumblist1[indexPath.item]
let imageUrl = URL(string: imageString)
let imageData = try? Data(contentsOf: imageUrl!)
DispatchQueue.main.async {
if (imageData != nil)
{
cell2?.verticalImageView.image = UIImage(data: imageData!)
}
}
}
return cell2!
答案 0 :(得分:2)
在致电imageUrl
之前检查您的image
是否为零:
DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async {
let imageString = self.thumblist1[indexPath.item]
if let imageUrl = URL(string: imageString) {
let imageData = try? Data(contentsOf: imageUrl)
DispatchQueue.main.async {
if (imageData != nil)
{
cell2?.verticalImageView.image = UIImage(data: imageData!)
}
}
}
}
return cell2!
}