ios - 重复使用的单元格在刷新图像时滞后

标签 ios swift tableview

这里的主要问题是我正在将图像加载到自定义单元格中,并且在滚动时,重用的单元格在加载新图像时显示旧图像。

坦率地说,不会有很多单元格,所以我的第一个想法是我可以使用 tableView.dequeueReusableCellWithIdentifier 解决问题,但是我尝试在每个地方尝试解决这个问题,或者人们质疑为什么有人会这样做,或者他们只是提供模糊的建议而没有某种示例。

在重新处理图像时没有这种滞后的情况下显示细胞的最佳方式是什么?

enter image description here

class FavoritesPropertyViewCell: UITableViewCell {
    @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
    @IBOutlet weak var cellPropertyImage: UIImageView!
    @IBOutlet weak var cellRoomsValue: UILabel!
    @IBOutlet weak var cellSpaceValue: UILabel!
    @IBOutlet weak var cellPriceRangeValue: UILabel!
    @IBOutlet weak var cellCityStateZipValue: UILabel!
    @IBOutlet weak var cellAddressValue: UILabel!

}

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{         


            var newPropertyCell: FavoritesPropertyViewCell = tableView.dequeueReusableCellWithIdentifier("FavoritesPropertyCell", forIndexPath: indexPath) as FavoritesPropertyViewCell

//... Get image, format values ...


                // Put everything in the labels.
                newPropertyCell.cellRoomsValue.text = roomsValue
                newPropertyCell.cellSpaceValue.text = spaceValue
                newPropertyCell.cellPriceRangeValue.text = priceValue
                newPropertyCell.cellAddressValue.text = addressValue
                newPropertyCell.cellCityStateZipValue.text = cityStateZipValue

                return newPropertyCell

    }

最佳答案

由于滚动速度与网络加载速度的关系,它无法解决使用标准 UIImageView 时的问题。

根据我的经验,使用图片缓存是肯定需要的。 有一些 cocoapods 实现图像缓存,你可以检查 AsyncImageView 或 NPRImageView

关于ios - 重复使用的单元格在刷新图像时滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29377521/

相关文章:

iOS 8 - 动画显示导航栏和状态栏无法正常工作

ios - 从 firebase 删除时数组索引超出范围

ios - GLSL ES 相当于 OpenGL GLSL 'out' 关键字?

swift - 在 Xcode UI Test 中定位没有辅助功能 ID 的元素

objective-c - 处理核心数据一对多关系

ios - 有没有办法调整 UITabBar 按钮项的宽度以适应屏幕上超过 5 个按钮?

ios - 在我调用 requestWhenInUseAuthorization() 之前触发位置权限对话框

ios - 如何在 View 中的特定点添加 subview

swift - 在 Swift 中的 TableView 之间传递数据

ios - 将 Iphone 应用程序更新为 Swift Coding