I want to add a UIWebView into a cell. THe HTML data will change and I will call reloadData when this happens.
Problem is, the UIWebView changes nicely but I can’t get the UITableViewCell to match the height properly. I’ve tried and failed at this solution…
When webview loads:
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
CGRect frame = aWebView.frame;
int old_height = frame.size.height;
frame.size = CGSizeMake(280, 0);
aWebView.frame = frame;
float content_height = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];
frame = aWebView.frame;
frame.size = CGSizeMake(280, content_height + 20);
aWebView.frame = frame;
NSLog(@"SIZES - %i - %i",old_height + 4,(int) frame.size.height);
if(old_height + 4 != frame.size.height){
[self.tableView reloadData];
}
}
Returned height for cell:
return webview.frame.size.height + 20;
After the first load the cell is not sized properly. It’s hard to figure out how to do this. I need to stretch the entire content downwards to fit a cell.
Thank you.
UIWebView isn’t designed to work inside another scroller (like UITableView);
And to resize the cell you should use either
UITableView.rowHeightproperty or the followingUITableViewDelegatemethod :- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPathAnd by the way, [UITableView reloadData] is normally a bad decision for updating the table.