2

我在 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 的限制时,我的应用程序意外退出导致内存压力。可能是什么原因?有什么解决办法吗?

4

1 回答 1

0

您是否将 Web 视图加载到表格视图的每个单元格中?这几乎可以肯定是个坏主意。表格视图单元被设计为屏幕高度的一部分,而不是 50,000 点高。

您可以将您的网络视图放入UIPageViewControlleror中UITabBarController吗?这两种容器控制器都具有为您管理屏幕外资源的优势,因此一次只有一个 Web 视图会占用内存。

于 2014-08-20T12:31:29.543 回答