Sabir Ali
Sabir Ali

Reputation: 141

UIWebView: calculating height of webview body content when reloading html dynamically?

When I call and loadHTMLString to load content in UIWebView, and calculating height of content of webview in didFinishLoad() method, it giving a height h, but if I again reload it with other HTML, it does not returning exact height of content if it is smaller than previous content, but by reloading again and again it reduces its height by a factor say 12 px and reach its exact height.

But if new content content height is greater than previous content height, it get calculated successfully.

Do anyone know the root cause why this happening this? If yes, please help.

Upvotes: 0

Views: 2187

Answers (1)

stack2012
stack2012

Reputation: 2186

This is what i did,though i had my webview within a uitableview in my case.

- (void)webViewDidFinishLoad:(UIWebView *)webview{
    float webHeight;
    CGRect frame = webview.frame;
    frame.size.height = 1;
    webview.frame = frame;
    CGSize fittingSize = [webview sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    webview.frame = frame;
    webHeight=fittingSize.height;
    rowHt=webHeight;
    [aTableView reloadData];
}

This delegate method will be called whenever the webview is reloaded. Here I set the frame size again to a new value. And again as i said i had my webview within a tableview so i call reloadData method. But this one worked fyn for me....

Upvotes: 4

Related Questions