Ios 表视图单元格中不显示图像
strong text我正在尝试将图像从Unsplash API下载到表视图中,但由于某些原因,它没有显示在表视图单元格中。根据文档,下载图像应该像这样“photo.url.raw” 下面是下载图像的逻辑。我如何解决这个问题 链接:Ios 表视图单元格中不显示图像,ios,mysql,swift,Ios,Mysql,Swift,strong text我正在尝试将图像从Unsplash API下载到表视图中,但由于某些原因,它没有显示在表视图单元格中。根据文档,下载图像应该像这样“photo.url.raw” 下面是下载图像的逻辑。我如何解决这个问题 链接: 如果您尝试设置调试点并检查流,您将发现您对以下代码的和平性存在问题: let cacheKey = NSString(string: urlString) //creates cacheKey to store in image variable let i
如果您尝试设置调试点并检查流,您将发现您对以下代码的和平性存在问题:
let cacheKey = NSString(string: urlString) //creates cacheKey to store in image variable
let imagesBaseURLSTring = imageURL.urls?.thumb ?? "No image"
// Here imagesBaseURLSTring is nil, so image is not downloaded and it is completed with nil. imagesBaseURLSTring is nil because of imageURL.urls is nil
guard let url = URL(string: imagesBaseURLSTring) else {
completed(nil)
return
}
这里imagesBaseURLSTring是nil,所以不下载图像,而是用nil完成。imagesBaseURLSTring为零,因为imageURL.URL为零。请检查您的逻辑,为什么为零
仅为了测试下载部件,您可以通过以下方式进行检查:
//let imagesBaseURLSTring = imageURL.urls?.thumb ?? "No image"
let imagesBaseURLSTring = urlString
//let imagesBaseURLSTring = imageURL.urls?.thumb ?? "No image"
let imagesBaseURLSTring = urlString