我们可以在不重新加载的情况下通过单击其中的按钮来更改 UITableViewCell
的内容大小吗?当我执行 reloadData()
或 reloadCell()
时,UITableView
闪烁,我想避免这种闪烁。
最佳答案
您应该使用 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
关于ios - 我们可以在不重新加载的情况下调整 UITableViewCell 的大小吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51265234/