2017-05-10 23 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