iOS - Collectionview图像在滚动时消失,有时会重叠

时间:2017-05-10 11:08:40

标签: ios uicollectionview dropbox

从服务器下载图像并填充集合视图(网格3 * n)时。我越来越毛病了。

我几乎尝试了一切,比如在重复使用单元格之前使图像视图为零,并使用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
}

1 个答案:

答案 0 :(得分:0)

如果不想完成图像下载的回调,请尝试此操作。

product_id = '" +product_id.Trim() + "'