Load async images in tableview with different cell height. Swift

530 Views Asked by At

The thing is i am making a request that brings me back some images with different height that i want to autoresize each cell according to each image, but when i paint them in the tableview, show wrong cell height ias all of them has same size, until i scroll them. The matter is that i had put UITableViewAutomaticDimension, estimate, autolayout constraints are ok.. and so on. But as images are receiving 2 or 3 secs after tableview has been loaded, i cannot refresh tableview nor reload it.

Any idea how can i fix this problem?

1

There are 1 best solutions below

2
On

The table view needs to refresh the cell heights now. Calling beginUpdates() and endUpdates() will force the table view to refresh the heights.

tableView.beginUpdates()
// set your image in cell here 
tableView.endUpdates()

There is also pretty nice tutorial: Self-sizing Table View Cells