views:

402

answers:

1

I have a set number of ViewControllers in my app. They are allocated and initialized at application launch and released at exit. They are used by a NavigationController to be pushed/popped. In these ViewControllers there are WebViews (actually there is nothing else).

My problem is : When I want to change de content (URL) of a WebView that is not on the current TopViewController, the content isn't loaded until I push/pop the associated ViewController.

And the transition us "ugly". The pushed/popped Viewcontroller shows old content at worst or blank page at best, before the ViewController is in full view THEN the new content is shown.

I tried lots of things (even putting the "loadRequest" in a different thread with looks stupid).

Do you know any way to make things go smooth?

A: 

In general you should plan your UI for slow UIWebView loads, because you can't plan ahead to know how long things will take. What I often do is have a UIView that has a spinner and a message such as "Loading..." that is layered on top of the UIWebView. Here's how I use it:

In viewWillAppear: I unhide the loading view and start the spinner.

In webViewDidFinishLoad I hide the loading view.

If webViewDidFail gets called, then you're not showing some interim or invalid content while the page loads. You can present a UIAlertView in that case.

If you're curious, you can see this in the high score page of my game (Lexitect, free)

Chris Garrett
The loading time isn't that long because the URL I load are local files. What I'ld like is really be able to preload the data, because, from my personal experience, it never gets loaded as long as the WebView isn't displayed on screen, even if i make and repeat the request, if I ask for a reload or a refresh, or a redraw of the view. The loading is always delayed, and that's the core of the problem I try to solve.
Cons