繁体   English   中英

为什么我在使用 kingfisher 将图像从 JSON 加载到 tableview 时出现错误?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM