6

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.

Papershine
  • 4,995
  • 2
  • 24
  • 48
Ashok
  • 180
  • 1
  • 7

1 Answers1

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