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.
Asked
Active
Viewed 2,485 times
6

Papershine
- 4,995
- 2
- 24
- 48

Ashok
- 180
- 1
- 7
-
3did you try tableview.beginUpdate and endUpdate ? – Prashant Tukadiya Jul 10 '18 at 12:31
-
1See https://stackoverflow.com/a/2063776/7104617 – Alexey Kudlay Jul 10 '18 at 12:35
-
i think you should add a wrapper view in contenview and then try changing its constraints on click of button. i hope this will work. – Abu Ul Hassan Jul 10 '18 at 12:41
-
updating content and then calling beginupdate() and endupdate() worked perfectly. – Ashok Jul 10 '18 at 16:45
1 Answers
15
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

Mahendra Y
- 1,941
- 20
- 26