我们可以在不重新加载UITableViewCell的情况下调整其大小吗?

时间:2018-07-10 12:28:36

标签: ios swift uitableview

是否可以通过单击UITableViewCell中的按钮来更改其内容大小而无需重新加载?当我reloadData()reloadCell() UITableView闪烁时,我想避免这种闪烁。

1 个答案:

答案 0 :(得分:8)

您应使用 beginUpdates() endUpdates()来更改 UITableViewCell 的内容大小,在这种情况下,应为 heightForRowAtindexPath 将为tableView中的每个单元格调用并更新TableviewCell的 height 。 对于 iOS> 10 ,您应该首选 performBatchUpdates(_:completion:),而不是beginUpdates()和endUpdates()。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.tableView.beginUpdates()
        self.tableView.endUpdates()
}

更多信息

https://appengineer.in/2018/07/11/resize-uitableviewcell-size-without-fluctuation-and-jerk/

https://developer.apple.com/documentation/uikit/uitableview/1614908-beginupdates

相关问题