tags:

views:

302

answers:

2

I'm trying to transition between loading of different web pages by hiding the webView while it is loading a page. However, I'm seeing that some image intensive websites are causing webViewDidFinishLoading to fire too soon and when I show the webView at that point then for a split second you get a view of the previous page. Any ideas on how to resolve this?

+1  A: 

I've encountered this problem as well. Although I haven't found a solution, I've worked around the problem by introducing a 0.5 second delay before showing the UIWebView once the webViewDidFinishLoading delegate method is called.

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self performSelector:@selector(displayWebView) withObject:nil afterDelay:0.5];
}
Pieter
+1  A: 

If there's Javascript on the page, you may need to wait for it to finish. The easiest way seems to be to send some javascript to the page to be executed:

-(void) webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *javaScript = @"<script type=\"text/javascript\">function myFunction(){return 1+1;}</script>";
    [webView stringByEvaluatingJavaScriptFromString:javaScript];

  // done here
}

Having said that, I seem to still see cases where the webview isn't quite updated within webViewDidFinishLoad.

Eric Shapiro