这是我的 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
}
答案 0 :(得分:1)
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
}
}