我正在加载一个webView到tableview。
textboby=[[UIWebView alloc]initWithFrame:CGRectMake(10, 250, 280, 1)];
textboby.userInteractionEnabled=YES;
textboby.scrollView.scrollEnabled=NO;
textboby.backgroundColor=[UIColor clearColor];
textboby.delegate=self;
textboby.tag=12;
[cell.contentView addSubview:textboby];
textboby.hidden=YES;
在webView中加载html字符串,如下所示:
htmlurl = [[NSBundle mainBundle] bundleURL];
NSString *htmlString =[[NSString alloc] initWithFormat: @"<html>"
"<head><meta charset="utf-8"> <style type="text/css">"
"body img{width:280px;background-color:black;}iframe{width:280px;background-color:black;}"
"</style></head>"
"<bod/Users/nuevalgo/Desktop/AjelProject/Aajil/AJDetailInView.hy style="font-family:'GE Dinar Two';width:280px;"><div style='direction:rtl;width:260px;white-space:pre-wrap;padding-right: 20px;'>%@</div>"
"</body>"
"</html>",detailobj.body];
[textboby loadHTMLString:htmlString baseURL:htmlurl];
我需要设置TableView行高度基于web视图偏移高度。我可以这样做:
-(void)webViewDidFinishLoad:(UIWebView *)webView{
detailTable.scrollEnabled = YES;
textboby.hidden=NO;
NSString *heighttmp=[textboby stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"];
CGRect adjustedFrame = textboby.frame;
adjustedFrame.size.height = 1;
textboby.frame = adjustedFrame;
CGSize frameSize;
frameSize = [textboby sizeThatFits:CGSizeZero];
adjustedFrame.size.height = frameSize.height ;
adjustedFrame.size.width=280;
textboby.scrollView.contentSize=CGSizeMake(280, frameSize.height);
textboby.frame = adjustedFrame;
height=[heighttmp intValue]+260;
[detailTable beginUpdates];
[detailTable endUpdates];
}
}
它工作正常,但是当[highttmp intValue]超过50,000的限制时,我的应用程序意外退出,导致内存压力。原因是什么呢?有解决办法吗?
您是否正在将web视图加载到表视图的每个单元格中?这几乎肯定是个坏主意。表格视图单元格被设计成屏幕高度的一小部分,而不是50000点高。
你可以把你的网页视图到UIPageViewController
或UITabBarController
代替?这两个容器控制器都有为你管理屏幕外资源的优势,这样一次只有一个web视图会占用内存。