2017-05-10 100 views
0

當從服務器下載圖像和填充集合視圖(電網3 * N)。我正在發生故障。的iOS - 的CollectionView圖像消失上滾動和有時重疊

我幾乎嘗試了一切可能像重用細胞,並使用GCD從主線程更新圖像視圖之前使圖像視圖爲零。

但我仍然面臨着小故障。

毛刺是,當我滾動集合視圖,下載重疊,有時圖像從集合視圖細胞消失。

我不知道是什麼原因造成的圖像消失(這曾經下載)。

任何建議。

private func cellForDropbox(cell:GridCell,indexPath:IndexPath) -> GridCell { 

    let filename = self.filenames[(indexPath as NSIndexPath).row] 

    cell.imageView.backgroundColor = UIColor.lightGray 
    cell.imageView.image = nil 

    DropboxClientsManager.authorizedClient?.files.getTemporaryLink(path: filename).response(completionHandler: { (response, error) in 

      if let url = response { 
       cell.imageView.sd_setImage(with: URL(string:url.link), placeholderImage: nil, options: .refreshCached, completed: { (img, error, cacheType, url) in 
       }) 

      } else { 
       print("Error downloading file from Dropbox: \(error!)") 
      } 
     }) 

    return cell 
} 
+0

你爲什麼要救圖像在緩存中。如果你已經使用SDwebImage。 – KKRocks

+0

@KKRocks:抱歉,現在刪除,你有這個想法? – user3804063

回答

0

如果不想完成圖像下載回調,請嘗試此操作。

private func cellForDropbox(cell:GridCell,indexPath:IndexPath) -> GridCell { 

    let filename = self.filenames[(indexPath as NSIndexPath).row] 

    cell.imageView.backgroundColor = UIColor.lightGray 

    DropboxClientsManager.authorizedClient?.files.getTemporaryLink(path: filename).response(completionHandler: { (response, error) in 

      if let url = response { 
      cell.imageView.sd_setImage(with: URL(string: url.link), placeholderImage: UIImage(named: "placeholder.png")) 


      } else { 
       print("Error downloading file from Dropbox: \(error!)") 
      } 
     }) 

    return cell 
} 
+0

沒有幫助一英寸:( – user3804063

+0

你可以下載cellForRowAtIndexPath? – KKRocks

+0

之外的圖像嗎?我想有一個網格視圖,它是非常瘋狂的,一塌糊塗。 – user3804063