2017-08-11 5 views
2

これは私のスウィフト3コードです。キングフィッシャーのキャッシュからダウンロードしている配列に画像を配置する必要があります。実際、画像は現在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

あなたはUIImage配列に画像を追加したい任意の特定の理由のような何かを行うことができますか? – kathayatnk

+0

はいセグの準備をして別のクラスに画像を渡す必要があります –

+0

ユーザーがセルをクリックしたときにこの画像を渡しますか?そうであれば、配列は必要ありません。 – Ramis

答えて

0
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 
    } 
} 
0

私はimageURlだけを渡すと信じています。あなたは以下の

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
    let currentImageUrl = self.FullLink[indexPath.row] 
    performSegue(withIdentifier: "YOU_SEGUE_IDENTIFIER", sender: currentImageUrl) 
} 


override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "YOUR_SEGUE_IDENTIFIER" { 
     if let desinationController = segue.destination as? UIViewController { 

      if let imageURL = sender as? String { 
       //make imageURL variable in destination controller 
       desinationController.imageURL = imageURL 
      } 
     } 
    } 
} 

//then on next controller you only have to set the imageviews with the url, since kingfisher will cache them, there will be no need to pass whole UIImage, just the link will suffice 

yourcontroller.imageView.kf.setImage(with: imageURL) 
関連する問題