is it possible to preload a webView before pushing it to the navigationController. Now the webView begins to load when the webview is visible.
Cya,
Tim
yeh load it into a UIWebView object. Then when you push the view, and assuming it is a different viewController, then "copy" your preloaded webView into your onscreen webview.
Just because you define an object doesn't mean you have to show it.
resurrecting an old thread to ask: does anyone have any example code for how to do this?
i have a view, loaded from a nib, which contains a UIWebView. into that web view i am loading html content from an html file in my bundle.
loading the content with loadHTMLString: seems to only work if i do it in my viewDidLoad: method, so you see a blank screen for a second before the content loads. this ruins the page curl animation because it should look like the content is on there already as it's animating.
so, i need to preload this html into the web view before displaying my view but i can't figure it out. halp!
I had the same problem. I had a webview in a ViewController that's pushed into a NavigationController stack. The animation started before my webview completed loading.
I solved it using the approach below. Note: I construct my objects programatically but you should be able to use the same idea with nibs:
1. I initialize and load the webview in the ViewController's initXXX function. This starts the loading process. I construct everything else in loadView (or viewDidLoad if using nibs).
2. My ViewController implements UIWebViewDelegate and waits for webViewDidFinishLoad. In this method I simply set a boolean property "ready" to YES and do other initializations as necessary (such invoking JavaScript functions).
3. Now I can init the ViewController, and then only push it to the NavigationController when its "ready" flag turns to YES (observed using Key Value Coding). This way I'm guaranteed the webview is preloaded.
I needed to wait for webViewDidFinishLoad for to fire some JavaScript anyway, so really it's just creating an additional observer to know when the webview has been fully rendered.
loading my html in my viewController's init function does not work, maybe it has something to do with the fact that i'm loading from a nib...?
my viewDidLoad function (where i am currently loading the html) seems like it's getting called only when i add my navigation controller to the view, just as the page curl animation begins.
console shows "loading html" just as the page curl animation starts, but the html content isn't rendered until a split-second after the animation ends. does it really take this long to load ~30 lines of html, or is something preventing the content from rendering right away?
if i move the loadHTMLString: stuff to my AboutViewController's init function it doesn't work at all, i get a white screen when the page flips down and no html loads.
ok, i came up with a unique solution to this problem. i am now successfully preloading the uiwebview with html content from a local file, and the page curl animation looks good. here's how i did it:
i noticed that the webview was refusing to load the content until it was in view. to solve this, i actually added the entire new view on top of my own view with a very low alpha (0.001), which would get the webview to render without making it visible. i temporarily set my root view controller as the UIWebViewDelegate so the web view would tell me when it was finished loading.
i then wait for the webViewDidFinishLoad: method to fire to apply the page curl animation, setting the alpha of my new About view to 1.0 as the animation starts and passing delegate responsibilities back to the new About view.
hope this helps someone else.
there are other ways that you could notify your root view that the webview is finished loading, but this works for me.
ok, i came up with a unique solution to this problem. i am now successfully preloading the uiwebview with html content from a local file, and the page curl animation looks good. here's how i did it:
i noticed that the webview was refusing to load the content until it was in view. to solve this, i actually added the entire new view on top of my own view with a very low alpha (0.001), which would get the webview to render without making it visible. i temporarily set my root view controller as the UIWebViewDelegate so the web view would tell me when it was finished loading.
i then wait for the webViewDidFinishLoad: method to fire to apply the page curl animation, setting the alpha of my new About view to 1.0 as the animation starts and passing delegate responsibilities back to the new About view.
hope this helps someone else.
there are other ways that you could notify your root view that the webview is finished loading, but this works for me.
Hey
I know this is an old thread but I'm running into the same issue could you please possibly send me the source or how you did this I'm a complete noob and I could use all the help thank you so much
chris
ok, i came up with a unique solution to this problem. i am now successfully preloading the uiwebview with html content from a local file, and the page curl animation looks good. here's how i did it:
i noticed that the webview was refusing to load the content until it was in view. to solve this, i actually added the entire new view on top of my own view with a very low alpha (0.001), which would get the webview to render without making it visible. i temporarily set my root view controller as the UIWebViewDelegate so the web view would tell me when it was finished loading.
i then wait for the webViewDidFinishLoad: method to fire to apply the page curl animation, setting the alpha of my new About view to 1.0 as the animation starts and passing delegate responsibilities back to the new About view.
hope this helps someone else.
there are other ways that you could notify your root view that the webview is finished loading, but this works for me.
Alright I can do all of this and it worked fine last night, but my mac crashed and I can't get it going again.
I have two viewcontrollers
OneViewController and TwoViewcontroller
Now the web delegate responds but nothing ever gets pushed - what's up with that? It's like push doesn't work when it's delegated that way. Do I have to do something goofy with my nib?
I found this only works if I insert a OneViewController object into the TwoViewController Nib and then link the oneViewController instance to the OneViewController object.
When webViewDidFinishLoad is called it alloc/inits a new SecondViewController object every time... maybe you should be pushing myWebView onto your main view controller rather than a new instance of SecondViewController.