Loading UIWebView content before displaying it

I have a certain number of ViewControllers in my application. They are allocated and initialized at application startup and freed upon exit. They are used by the navigation controller to push / push. These ViewControllers have WebViews (there really is nothing else).

My problem: When I want to change the content (URL) of a WebView that is not in the current TopViewController, the content does not load until I click / enable the corresponding ViewController.

And the transition is ugly. The extended / pulled Viewcontroller shows, at best, the old content at worst or a blank page before the ViewController is in full screen. Then the new content will appear.

I tried a lot of things (even putting "loadRequest" on another thread, looking stupid).

Do you know how to make things smooth?

+6
iphone uiwebview
source share
1 answer

In general, you should plan your user interface for slow UIWebView downloads because you cannot plan ahead to find out how long it takes. What I often do is a UIView that has a counter and a message, such as "Loading ..." that overlays on top of the UIWebView. Here is how I use it:

In the WillAppear: view, I display the view of the load and start the counter.

In webViewDidFinishLoad I hide the view of the load.

If webViewDidFail is called, you are not displaying intermediate or inappropriate content while the page is loading. In this case, you can submit a UIAlertView.

If you're interested, you can see it on the high-rated page of my game (Lexitect, free)

0
source share

All Articles