Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we resize UITableViewCell without reloading it?

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.

like image 977
Ashok Avatar asked Jul 10 '18 12:07

Ashok


1 Answers

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

like image 120
Mahendra Y Avatar answered Sep 23 '22 14:09

Mahendra Y