我有一个tableview,我想做的就是在单击单元格时将webview添加到一个单元格上,而且该特定单元格的高度也应根据webview内容进行调整。
建议欢迎。

最佳答案

这取决于您拥有Web视图的单元格的数量。理想情况下,您必须等待Web视图呈现,然后更改Web视图和单元格的高度

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *string = [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"body\").offsetHeight;"];
    CGFloat height = [string floatValue] + 8;
    CGRect frame = [_webView frame];
    frame.size.height = height;
    [_webView setFrame:frame];

//Store the height in some dictionary and call [self.tableView beginUpdates] and [self.tableView endUpdates]
}

当然,这会带来不好的性能影响,但是对于单个单元格来说,这还不错。如果有多个单元格具有网络视图,请使用 Ishank的方法。但是,如果您的字符串包含div元素(例如<td>),则该方法将返回误导的高度。

10-05 20:24
查看更多