ios - 具有异步图像加载的自调整单元格大小

标签 ios swift uitableview autolayout lazy-loading

更新:这个Github链接包含项目。如果可能,请下载并点击顶部的重新加载,您将了解其中的区别。和先生Zhang感谢您提出“要填充的纵横比”建议。它对我帮助不大。

我有一个异步加载图像的 TableView (使用 AFNetworking UIImageView 类别类)。图像第一次在可见单元格上压缩。一旦我再次重新加载或滚动 op 和向下,图像就会根据其大小进行调整。

基本上我会得到不同尺寸的图像。哪个宽度应该是单元格宽度,高度可以是任何东西

实现了 self 调整的所有必要步骤(适当的自动布局约束和适当的委托(delegate)方法)

//my tableview setup     
self.tblTest?.estimatedRowHeight = 1000.0 //i've tried with all possible guesses and 
//tried with delegate also 
self.tblTest?.rowHeight = UITableViewAutomaticDimension

我添加了如下约束:

enter image description here

在我的测试单元中。

func setUpImage(url:NSURL){
  //tried with another function also without NSURLRequest
    self.imvTest?.setImageWithURLRequest(NSURLRequest(URL: url),
                                        placeholderImage: UIImage(named: "store_placeholder"),
                                        success: { (requset, response, image) -> Void in
        self.imvTest?.image = image
        print(image.size)

        }, failure: { (error) -> Void in

            self.imvTest?.image = nil
    })
}

结果

enter image description here

预期

enter image description here

如何防止第一次图片压缩?

P.S:我认为每次重新加载表格 View 和设置图像的时间是不正确的。

请告诉我我遗漏了什么以及任何内容优先级等,??

最佳答案

试着打电话

tableView.beginUpdates()
tableView.endUpdates()

成功闭包中设置图片后

或者在设置图像后用单元格的indexPath尝试tableView.reloadRowsAtIndexPaths

关于ios - 具有异步图像加载的自调整单元格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34707556/

相关文章:

ios - 如何运行两个 React Native 应用程序?

ios - 从 JSON 中获取对象

cocoa - Swift 中的类不符合 'CBPeripheralManagerDelegate'

ios - UIBezierPath 填充 UITableViewCell 中自定义 UIView 中的偏移量

ios - 如何让uitableview在顶部滚动时不被拉动

ios - React Native - 如何在 ActionSheetIOS 选项参数中使用 excludedActivityTypes 属性?

ios - 在 Swift 中对字典数组进行排序

ios - 卡里斯塔 OBD ||与 iOS 设备的设备通信

ios - 增加 1 UITableViewCell 分隔符高度

iphone - 将 UITableView 信息存储在单个 NSMutableArray 中