1

我正在使用带有动态单元格的 UITableView。每个单元格都有一些按钮、一个图像和一个标签。图像的宽度等于 tableview 的宽度,高度是可变的。

我正在通过函数更新 cellForRowAtIndexPath 中图像的高度...以尊重纵横比。标签可以有 1 行或多行。

我正在使用 heightForRowAtIndexPath 来设置单元格的高度。我在那里计算并返回值。

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    let queficient = CGFloat(dataController.Data[indexPath.row].width) / self.view.frame.size.width

    let imgHeight = CGFloat(dataController.Data[indexPath.row].height) / queficient

    return 134 + imgHeight + heightForView(dataController.Data[indexPath.row].description)
}

我不知道为什么当我滚动时表格有点迟钝和跳跃。

4

1 回答 1

0

如果您确定滞后是由 heightforRowAtIndexPath 引起的,为什么不只计算一次每个单元格数据/索引路径的高度,当图像发生变化时?

你应该只返回 dataController.Data[indexPath.row].calculatedCellHeight 什么的

于 2015-09-29T15:42:59.133 回答