gpt4 book ai didi

swift - 如何将图像放入由 Kingfisher 缓存下载的数组中?

转载 作者:搜寻专家 更新时间:2023-10-31 22:41:29 24 4
gpt4 key购买 nike

这是我的 Swift 3 代码。我需要将图像放入通过 Kingfisher 缓存下载的数组中。实际上,图像现在显示在 cell.itemImage 中,但我无法将这些图像放入 UIImage 数组。

有人能帮忙吗?

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! ViewItemsCVC
let Currency = UserDefaults.standard.string(forKey: "currency")
cell.NameLabel.text = self.itemName[indexPath.row]
cell.PriceLabel.text = "\(Currency ?? "INR") \(self.itemPrice[indexPath.row])"
let resource = ImageResource(downloadURL: URL(string: self.FullLink[indexPath.row])!, cacheKey: self.FullLink[indexPath.row])
cell.itemImage?.kf.setImage(with: resource)
return cell
}

最佳答案

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
switch segue.destination {
case let viewController as YourViewController:
let row = collectionView.indexPathsForSelectedItems?.first?.row
let image = ImageResource(downloadURL: URL(string: self.FullLink[row])!, cacheKey: self.FullLink[row])
viewController.image = image

default:
break
}
}

关于swift - 如何将图像放入由 Kingfisher 缓存下载的数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45628266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com