I have collection view where in cell I put UITableView. Two of cells in that table view contains UIWebView. I need to calculate height dynamically of UIWebViews. So I do next in
- (void)webViewDidFinishLoad:(UIWebView *)webView
..... CGFloat webViewHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"]floatValue];
But problem is that height on result calculates using content that was upload previously when this cell was used for another object from array. I have try to fix that problem using next thing [webView stringByEvaluatingJavaScriptFromString:@"document.body = \"\";"]; But it doesn't help me. It works fine at simulator but buggy at device. + If I put delay before upload new html
[webView loadHTMLString:sourceHTML baseURL:nil];
I could see previous content that leads to calculating to wrong height.
Update 1 Here is solution that works perfect for me
CGRect frame = webView.frame;
frame.size.height = 1;
webView.frame = frame;
frame = webView.frame;
frame.size = [webView sizeThatFits:CGSizeZero];
webView.frame = frame;
And from frame I can get correct height.