Dynamic UITableViewCell with UIWebView

I have an array of HTML strings, some of them with photos, some of them long, some short, some with links - they are all different.

Now I have it UITableView, and I want to display these HTML lines in the table, each line in each cell at this index. My problem is that I don’t know the height of each cell, I need to calculate the height by height of each line of HTML, but I can only know it after loading UIWebView.

I need a suggestion for a good solution to this problem that will look good. I already tried to use UIWebViewDelegateto change the frame of the cell after loading the HTML string in the WebView, but it looks bad .. and it scans the table view completely randomly.

Thanks in advance.

+4
source share
1 answer

Enjoy the animation while adding cells.

Add cells one at a time (one at a time) to your UITableView( and data source) by doing the following:

    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:@[indexPath]
                          withRowAnimation:UITableViewRowAnimationFade];
                          // or UITableViewRowAnimationNone
    [self.tableView endUpdates];

Yours UITableViewwill grow slowly with animation as the data becomes available.

If you need to resize an existing cell , delete it and reinsert it immediately, all within the same sequence beginUpdates / endUpdates:

    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:@[indexPath]
                          withRowAnimation:UITableViewRowAnimationFade];
    [self.tableView insertRowsAtIndexPaths:@[indexPath]
                          withRowAnimation:UITableViewRowAnimationFade];
    [self.tableView endUpdates];
+1
source

Source: https://habr.com/ru/post/1547312/


All Articles