I've got a UITableView holding UIWebView
s of variable height, and the user has the ability to edit the content of each web view. The content of each cell (a web view) is linked to a NSManagedObject
subclass that has the height of the content stored as contentHeight
. When a new set of content is initially created, it is filled in with a default set of data that has a set height, so there is no issue there.
My problem arises when the user edits the content of a web view; I need to figure out the height of the new content and update the tableview accordingly. I've already set up the logic for updating the saved contentHeight
variable for the corresponding object, but I cannot find a reliable method to determine the height of the new content. Below I've listed a few of the methods I've tried and haven't been able to make work. ANY help would be greatly appreciated, I've been stumped for over an hour now :(
FAILED METHODS:
[[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] floatValue];
[[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
[[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
[[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('sdcontent').offsetHeight"] floatValue];
CGRect webViewFrame = [webView frame];
CGRect temp = webViewFrame;
webViewFrame.size.height = 1;
[webView setFrame:webViewFrame];
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
webViewFrame.size = fittingSize;
[webView setFrame:temp];