Reputation: 5150
I have an array of HTML strings, some of them are with photos, some of them long, some short, some with links - they are all different.
Now I have a UITableView
and I want to display those HTML strings on the table, each string in each cell by it's index. My problem is that I don't know the height of each cell, I need to calculate the height by the height of each HTML string, but I can only know it after the UIWebView
is loaded.
I need a suggestion for a good solution to this issue, something that will looks good. I've already tried to use UIWebViewDelegate
to change the cell frame after loading the HTML string into the WebView but it looks bad.. and messes the table view completely.
Thanks in advance.
Upvotes: 4
Views: 906
Reputation: 48514
Resort to animation when adding the cells.
Add the cells one by one (1 indexPath at a time) in your UITableView
(and datasource), by doing this:
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
// or UITableViewRowAnimationNone
[self.tableView endUpdates];
Your UITableView
will slowly grow with an animation as the data becomes available.
If you need to resize an existing cell, delete it and immediately re-insert it, all within a single beginUpdates/endUpdates sequence:
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
Upvotes: 1