如何从 cellForRowAtIndexPath 更改行高?
How can I change row height from cellForRowAtIndexPath?
我需要使用 UITableView 在 cellForRowAtIndexPath 中更改行高。
heightForRowAtIndexPath 在 cellForRowAtIndexPath 之前执行,但在 cellForRowAtIndexPath 中,我将内容设置为行,具体取决于必须重新计算的高度。
你不能,你唯一可以而且应该改变的地方是 heightForRowAtIndexPath
但是对于你的问题还有其他解决方案,解释得很好here
我建议您检查启用行高估计的第三个解决方案。
您可以在 viewDidLoad 中为所有单元格设置高度
self.tableView.rowHeight = 88.0
或使用事件 heightForRowAt,其中您有单元格 IndexPath
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 88.0
}
我需要使用 UITableView 在 cellForRowAtIndexPath 中更改行高。
heightForRowAtIndexPath 在 cellForRowAtIndexPath 之前执行,但在 cellForRowAtIndexPath 中,我将内容设置为行,具体取决于必须重新计算的高度。
你不能,你唯一可以而且应该改变的地方是 heightForRowAtIndexPath
但是对于你的问题还有其他解决方案,解释得很好here
我建议您检查启用行高估计的第三个解决方案。
您可以在 viewDidLoad 中为所有单元格设置高度
self.tableView.rowHeight = 88.0
或使用事件 heightForRowAt,其中您有单元格 IndexPath
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 88.0
}