SHANIBA P M
SHANIBA P M

Reputation: 21

UIWebView app crashes with memory pressure

I am loading a webView inside the 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;

And loaded the html string in the webView as below:

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];

I need to set the TableView row height based on the web view offset height. I was able to do this as below:

-(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]; 
}

}

It is working properly, but when the [heighttmp intValue] exceeds a limit of 50,000 my App exits unexpectedly causing a memory pressure. What could be the reason? Is there any solution?

Upvotes: 2

Views: 559

Answers (1)

jemmons
jemmons

Reputation: 18657

Are you loading a web view into each cell of a table view? This is almost certainly a bad idea. Table view cells were designed to be fractions of the screen height, not 50,000 points tall.

Can you put your web views into a UIPageViewController or UITabBarController instead? Both these container controllers have the advantage of managing off-screen resources for you so that only one web view will hog memory at a time.

Upvotes: 0

Related Questions