I'm downloading multiply htmls and save them locally as strings in an NSArray
.
Then I'm using 3 UIWebViews
to load the content. The user always sees one UIWebView
and 2 more UIWebViews
are loaded in the background using:
[_firstWebView loadHTMLString:nextHtml.body baseURL:nil];
When the user moves around between UIWebViews
I can still see slow loading times of 1-2 seconds if he moves 2 UIWebViews
at a time. I thought about going to 5 or even 7 UIWebViews
but I'm afraid it will impact the memory usage heavily.
Another thought I had was saving the content locally as NSData
and then load it with
[web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
But I'm not sure that will gain me any improvement or will it?
Another thought was that something in my app (animation on the screen) is slowing down the loading time so maybe I should loadHTMLString:nextHtml
on a different thread?
Thanks
Recently I did some research about loading content to UIWebView in the background. I've found that even successful loadRequest has no effect while webview is invisible and not added as subview somewhere.
But if I make some access to view before loading, it starts to show content loaded in the background.
So I hide the view first, then load content in it and before showing it to user make the view visible again:
In loading method:
When user switches to the webview:
This approach worked for me. Hope it also point you in right direction.