我有一个tableview,我想要做的是在单元格上添加webview,因为我们点击单元格,加上该特定单元格的高度也应该根据webview内容进行调整。 建议欢迎。在UITableViewCell中添加UIWebView
2
A
回答
0
在委托 - cellForRowatIndex:
,你可以做这个 -
NSString *HtmlStr = [NSString stringWithFromat:@"<div style=\"font-family:\"Times New Roman\";font-size:18px;\">%@</div>",@"YOUR_String_DATA"];
[cell.webView loadHTMLString:HtmlStr baseURL:nil];
使用这个 -
CGSize aSize = [@"YOUR_String_DATA" sizeWithFont:@"Times New Roman" minFontSize:18.0f actualFontSize:18.0f forWidth:TableViewCellWidth lineBreakMode:lineBreakMode];
cell.webView.frame = CGRectMake(0,0,aSize.width,aSize.height);
此外,在heightForRowatIndex:
委托方法查找内容大小(在你的案件高度)U必须以某种方式返回高度aSize.height
2
它取决于您拥有网页视图的单元格的数量。理想情况下,你将不得不等待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]
}
当然,这将需要一个坏的性能比较命中,但对于一个单细胞,这是不坏。如果万一有多个单元格有Web视图,请使用Ishank的方法。但是,如果您的字符串包含像<td>
这样的div元素,该方法将返回一个令人误解的高度。
相关问题
- 1. 如何在UITableViewCell中动态添加UIWebview?
- 2. UITableViewCell中的UIWebView
- 3. 在UIWebView中添加UIButton
- 4. 在UIWebView中添加图像
- 5. 通过单击UITableViewCell将UIWebView加载到UINavigationController后不加载UIWebView
- 6. 将UIWebView合并到UITableViewCell中
- 7. UIWebView在自定义UITableViewCell
- 8. 添加UIWebView MKPinAnnotationView.detailCalloutAccessoryView
- 9. 动态UITableViewCell与UIWebView
- 10. 的UIWebView在UITableViewCell中的显示在我的UITableViewCell定义图标
- 11. 的UITableViewCell错误加载一个UIWebView
- 12. UIWebView没有在UITableViewCell中定位
- 13. UITableViewCell中的UIWebView在滚动时刷新
- 14. 在UITableViewCell中加载UIWebView,并根据UIWebview的内容制作UITabViewCell的高度
- 15. iphone UITableViewCell中添加图像
- 16. 如何在UIAlertView中添加UIWebview?
- 17. 在Xcode中添加HTML文件的UIWebView
- 18. 在UITableViewCell中添加多个UITableViews
- 19. 在UITableViewCell中为detailTextLabel添加右边距
- 20. 添加动态的UIImageView在UITableViewCell中
- 21. 如何在uitableviewcell中添加ImageButton
- 22. 在UITableViewCell中添加UICollectionView时出错
- 23. 如何在UITableViewCell中添加视频
- 24. 如何在UITableViewCell中添加图片
- 25. 在UITableViewCell中添加分隔符
- 26. 在uitableviewcell中添加多个imageview iphone
- 27. 在UITableViewCell的子视图中添加UIViewController
- 28. 如何在UITableViewCell中添加UIProgressView
- 29. 如何滚动的UIWebView添加到一个UITableViewCell中的iOS 3.X?
- 30. 如何在单击UITableViewCell时导航UIWebView?
您是否使用自动布局? – 2013-04-22 09:37:03
我只是支持IO6 – Suhaiyl 2013-04-22 09:44:22
是使用AutoLayout,但在tableviewcell中加载webviews似乎是沉重的操作。 :( – Suhaiyl 2013-04-22 09:45:23