iOS-Collectionview图像在滚动时消失,有时会重叠 [英] iOS - Collectionview images disappear on scrolling and sometimes overlaps

查看:206
本文介绍了iOS-Collectionview图像在滚动时消失,有时会重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从服务器下载图像并填充收集视图时(网格3 * n)。我正在小故障。

When downloading images from server and populating the collection view (grid 3 * n). I am getting glitch .

我几乎尝试了所有可能的方法,例如在重新使用单元格之前使图像视图为零,并使用GCD从主线程更新图像视图。

I tried almost everything possible like making image view nil before reusing cell and using GCD for updating image view from main thread.

但是我仍然面对故障。

小故障是当我滚动收集视图时,下载的图像重叠,有时会从收集视图单元中消失。

Glitch is when I scroll the collection view , images downloaded are overlapped and sometimes disappear from the collection view cell.

我不知道是什么原因导致图像消失(曾经下载过)。

I have no idea what is causing the image to disappear (which were once downloaded).

任何建议

    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
}


推荐答案

如果这样做,请尝试

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
}

这篇关于iOS-Collectionview图像在滚动时消失,有时会重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆