TableView嵌套WebView

东郭海阳
2023-12-01

详解

思路:
1.将webView放入tableViewCell上面(contentView)

[cell.contentView addSubview:_webView];

2.在-(void)webViewDidFinishLoad:(UIWebView *)webView 设置 webView高度

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    //获取到webview的高度
    CGFloat height = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
    self.webView.frame = CGRectMake(self.webView.frame.origin.x,self.webView.frame.origin.y, SCREENWIDTH, height);
    [self.tableView reloadData];
}
 类似资料: