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

标签 ios swift uitableview

我们可以在不重新加载的情况下通过单击其中的按钮来更改 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/

相关文章:

iphone - 如果使用其他 NSMutableArray 初始化,如何更新 NSMutableArray

ios - 在 iOS 中使用刷新的 OpenURL?

swift - 以编程方式初始化 TableView 单元格与 dequeueForReusableIdentifier

swift - 在 View Controller 之间传递数据使用从导航 Controller 中嵌入的 View 到 tabbarcontroller 的 segue

ios - 快速删除表格 View 中的一行

ios - Swift 分组 UITableView 最佳实践

ios - 使自定义事件指示器 View 的 UIView 半透明

ios - 页面控件在完全转到下一页之前切换页面

ios - Swift - 如何获取当前时间(以秒为单位)?

ios - 如何在 Swift 中以编程方式将 HeaderView 从 nib 添加到 UiTableView