Viktoria
Viktoria

Reputation: 129

heightForRowAtindexPath not called after tableView.beginUpdates in ios 15

Before iOS 15 after I made

self.tableView.beginUpdates()
self.tableView.endUpdates()

method heightForRowAtindexPath was called and my cell height changed without reloading data in the cell. Now in iOS 15 this not works! How can I force reload tableview cell height without reloading data in this cell?

Upvotes: 8

Views: 1700

Answers (2)

Carlos Guzman
Carlos Guzman

Reputation: 363

I have already solved the problem. Apparently, Apple made a change in the way updates are processed and cell sizes are adjusted.

As the "hidden" cell is left at 0, when sending the beginUpdate, it only processes the cells that have a value greater than 0, so that is why it no longer adjusts them.

What you need to do is change the value of 0, returned for hidden cells, to 0.01, and you're done!

I hope this solution works the same for me.

Upvotes: 6

Viktoria
Viktoria

Reputation: 129

Found a solution:

  1. In heightForRowAtindexPath method return for resizable cell UITableView.automaticDimension instead of size
  2. Inside my custom tableView cell I added height constraint to my container view (in my case this is webView)
  3. In a place where I get cell size and need to update height (for me after webView content was loaded), I update height contraint:

.

cell.heightContraint.constant = size
self.tableView.beginUpdates()
self.tableView.endUpdates()

So the cell is autoresizable now with UITableView.automaticDimension height and, of course, your view/container view should have top and bottom constraints equal to cell`s top and bottom constraints

Upvotes: 0

Related Questions