我在tableview中加载了一个webView。
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];
我需要根据Web视图偏移高度设置TableView行高。 我能够做到如下:
-(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];
}
}
它工作正常,但当[heighttmp intValue]超过50,000的限制时,我的应用程序意外退出导致内存压力。可能是什么原因?有没有解决方案?
答案 0 :(得分:0)
您是否正在将网络视图加载到表格视图的每个单元格中?这几乎肯定是一个坏主意。表视图单元被设计为屏幕高度的一部分,而不是50,000点高。
您可以将自己的网络视图改为UIPageViewController
或UITabBarController
吗?这两种容器控制器都具有为您管理屏幕外资源的优势,因此一次只能有一个Web视图占用内存。