我们可以在不重新加载的情况下调整 UITableViewCell 的大小吗? [英] Can we resize UITableViewCell without reloading it?

查看:33
本文介绍了我们可以在不重新加载的情况下调整 UITableViewCell 的大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在不重新加载的情况下单击其中的按钮来更改 UITableViewCell 的内容大小吗?当我执行 reloadData()reloadCell()UITableView 闪烁,我想避免这种闪烁.

Can we change the content size of UITableViewCell on click of a button inside it without reloading? When I do reloadData() or reloadCell() UITableView flickers and I want to avoid this flickering.

推荐答案

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

You should use beginUpdates() and endUpdates() to change content size of UITableViewCell, in this case heightForRowAtindexPath will called for each cell in tableView and update height of TableviewCell. for iOS > 10, You should prefer performBatchUpdates(_:completion:) instead of beginUpdates() and 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-开始更新

这篇关于我们可以在不重新加载的情况下调整 UITableViewCell 的大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆