2017-10-09 13 views
0

AlamofireImageでサーバからサムネイルをダウンロードして表示していますが、ダウンロードはうまく動作しますが、tableivewセルの画像が常に変化するときは検索していません。例えばprepareForReuseカスタムセル呼び出しでここに私のコードです:AlamofireImageでテーブルビューのセル画像を表示する際の問題

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TrendingCell 

     let trendingIndex = trendingArray[indexPath.row] as! [String:Any] 

     if let media = trendingIndex["thumbnails"] as? [String:Any] { 
      if let thumbnail = media["medium"] as? [String:Any] { 
       thumbnailURL = String(describing:thumbnail["url"]!) 
      } 
     } 



     Alamofire.request(thumbnailURL).responseImage { response in 
      if let image = response.result.value { 
       cell.thumbnail.image = image 
      } 

     } 

     return cell 
    } 

ユーザーがテーブルビューをスクロールすると画像が変わるのを避けるにはどうしたらいいですか?

+0

https://stackoverflow.com/questions/46199203/downloading-uiimage-via-alamofireimage/46199246#46199246 –

+0

私はイメージのため、[SDWebImage](https://github.com/rs/SDWebImage)ライブラリを使用することをお勧めし – Srdjan

+1

セルを使用して記述する必要があります。imageView –

答えて

1

サルマンGhumsaniはhereを述べたように:

を、私たちはこのように、デフォルトのサムネイルを設定するAlamofireImage拡張子を使用することができます。

//Download and set thumbnail 
     if let imageURL = URL(string: thumbnailURL), let placeholder = UIImage(named: "Default") { 
      cell.thumbnail.af_setImage(withURL: imageURL, placeholderImage: placeholder) //set image automatically when download compelete. 
     } 

あなたがテーブルビュー画像をスクロールしたときに今すぐ変更されませんでした。

+0

答えを受け入れる – Vinodh

関連する問題