Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change uitableviewcell's height after tableView.reloadData

I am working on a twitter-like client, and there is a message list view implemented by UITableView. For each cell, it may need to load a dynamic size image, and the image is loaded async. So it size of the image is unknown when the table view loaded.

Is it possible to update the uitableviewcell's height after the image is loaded.

From my knowledge, the only way to update the height is in this method: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath But it is just called when loading data at first time. This is reasonable from performance consideration. Anyhow, is there a way to change the height later?

Thanks for any information!

Finally, I used "reloadRowsAtIndexPaths" to update particular rows, you can try this for hidden cells.

[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:toReloadRows withRowAnimation: UITableViewRowAnimationNone];
[self.tableView endUpdates];

But, the cell shakes when updating the visible cells's height. So the it's better to have the cell height calculated before.

like image 499
Fourj Avatar asked Mar 16 '11 08:03

Fourj


1 Answers

Try calling an empty Update block:

[self.tableView beginUpdates];
[self.tableView endUpdates];

This seems to work for visible cells. I'm still struggling with hidden cells.

like image 61
hanno Avatar answered Oct 02 '22 14:10

hanno