我使用表格 View 单元格的动态高度和 Haneke 使用以下代码下载和缓存图像:
override func viewDidLoad() {
super.viewDidLoad()
myTableView.rowHeight = UITableViewAutomaticDimension
myTableView.estimatedRowHeight = 500
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:ImageCellTableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ImageCellTableViewCell;
cell.myImageView.hnk_setImage(from: URL(string: imageUrl), placeholder: nil)
return cell
}
这里我需要在下载后设置图像时调整单元格高度。 下载图像后如何调整表格 View 单元格的大小。
最佳答案
只需调用
tableView.beginUpdates()
tableView.endUpdates()
下载图像并设置高度约束后。希望这有帮助!
编辑:
另一种选择是从服务器接收图像大小,为单元格提供正确的高度。这样您就可以为表格提供正确计算的单元格高度。
关于ios - 加载图像后调整 UITableViewCell 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46540860/