I'm experimenting with a magazine kind of iPad app that I develop and I ran into a memory issue. There are multiple UIWebView-s on a UIScrollView. Every UIWebView displays an html page each from html file source. Unfortunately I couldn't find the solution to handle the web views to load them smoothly in the background once the app loaded, instead of that it loads and fires every html pages with all its javascripts and images, because I want them to be visible once I swipe through on them, hovewer I get "Received memory warning" message at 30 panels and the app breaks.
The code I use to display the web views is this:
NSInteger numberOfViews = 47;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * 768;
DetailViewController *detailViewController2 = [[DetailViewController alloc] initWithNibName:@"Detail" bundle:nil];
[detailViewController2.view setFrame:CGRectMake(yOrigin, 0, 768, 1024)];
detailViewController2.view.clipsToBounds = YES;
[scroll.view insertSubview:detailViewController2.view atIndex:0];
}
scroll.scrollView.contentSize = CGSizeMake(768 * numberOfViews,1004);
scroll.pageControl.numberOfPages = numberOfViews;
self.view.clipsToBounds = YES;
self.view.clearsContextBeforeDrawing = YES;
CGRect frame;
frame.origin.x = scroll.scrollView.frame.size.width * scroll.pageControl.currentPage;
frame.origin.y = 0;
frame.size = scroll.scrollView.frame.size;
[scroll.scrollView scrollRectToVisible:frame animated:NO];
self.scrollViewController = scroll;
[self.view insertSubview:scroll.view atIndex:0];
- (void)dealloc {
[scrollViewController release];
[tableOfContentsViewController release];
[portrait release];
[tableOfContents1 release];
[start release];
[super dealloc];
}
The code that displays the html content is inside the DetaildViewController:
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:htmlfilename
ofType:@"html"
inDirectory:@"/htdocs" ];
NSString *html = [NSString stringWithContentsOfFile:htmlPath
encoding:NSUTF8StringEncoding
error:nil];
web.delegate = self;
[web setMultipleTouchEnabled:YES];
[web loadHTMLString:html
baseURL:[NSURL fileURLWithPath:
[NSString stringWithFormat:@"%@/htdocs/",
[[NSBundle mainBundle] bundlePath]]]];
- (void)dealloc {
//---release the memory used by the property---
[page release];
[web setDelegate:nil];
[web stopLoading];
[web release];
[orientation release];
[page release];
[super dealloc];
}
The question is how I can load them smoothly in the backround on the UIScrollView and only fire the javascripts once the panel bounces into the viewport, I plan to display more than 60 webviews with its html pages?