Reputation: 180
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.
Upvotes: 6
Views: 2864
Reputation: 1949
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()
}
For more information
https://appengineer.in/2018/07/11/resize-uitableviewcell-size-without-fluctuation-and-jerk/
https://developer.apple.com/documentation/uikit/uitableview/1614908-beginupdates
Upvotes: 15