[英]Why am I getting error at loading image from JSON to tableview using kingfisher?
我正在尝试借助Kingfisher
库将从 JSON 响应中获得的图像加载到tableView
中。 这是从 JSON 响应获得的图像:
"image": "/static/restaurants/image-1593600873191.jpg"
现在我在cellForRow
方法中编写这段代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.lblName.text = arrUsers[0].data?.categories[0].name
let url = URL(string:arrUsers[0].data?.bestOffers[0].image ?? "No Url")
cell.imgName.kf.setImage(with: url)
return cell
}
在上面的代码中,我将图像的 JSON 响应转换为 URL 然后将其传递给setImage
方法。
label 被设置到tableView
但图像没有被加载到tableViewCell
并且我在控制台中收到此错误。 请找到随附的屏幕截图以供参考。
更改此行:
let url = URL(string:arrUsers[0].data?.bestOffers[0].image ?? "No Url")
至
let url = URL(string: "https://yourwebsiteaddress" + (arrUsers[0].data?.bestOffers[0].image ?? "No Url"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.