0

I'm using webViewDidFinishLoad a lot in my app and there's something about UIWebView that really bugs me, well, actually two things. The first, when I load new content to a UIWebView I will see for half a second the last page that was loaded to the same UIWebView what will force me to "clean" the UIWebView using something like:

[_mainWebView stringByEvaluatingJavaScriptFromString:@"document.open();document.close();"];

before loading the new content.

The second issue I have and that's the main issue for this question is that if i'll load some new content to my UIWebView and do something like this:

[_mainWebView loadHTMLString:htmlString baseURL:nil];
...
    - (void)webViewDidFinishLoad:(UIWebView *)webView {
            _mainWebView.alpha = 1;
    }

In some cases the UIWebView will show up white for half a second before showing up the content. I'm guessing that the content is already loaded into the UIWebView and that's why webViewDidFinishLoad:webView is firing but for small html pages showing to content takes loner than the actual load. Is there any workaround I can use to avoid the blank screen that is showing for a sec or so but still save that second?

I thought about animating the alpha from 0 to 1 but that solution feels kinda lame to me.

Segev
  • 19,035
  • 12
  • 80
  • 152
  • Do you have control over the html? Or you're willing to download and manipulate the html? If so, you could add some javascript to the page that runs a callback in your app... – Wain Apr 14 '13 at 11:10
  • I download the htmls before displaying it. Sounds interesting, I'm willing to try. :) – Segev Apr 14 '13 at 11:18
  • The code shown isn't really much to go on. Please can you provide some more to show exactly what you are doing. – Popeye Apr 14 '13 at 11:33
  • I adde done line of code to make it more understood but the only thing I'm doing is loading an html into a webview and showing the webview when it's loaded. The problem is that the webview is shown before the content is loaded because of the `UIWebView` background thread as described here: http://stackoverflow.com/questions/2311564/reused-uiwebview-showing-previous-loaded-content-for-a-brief-second-on-iphone/2311935#2311935 – Segev Apr 14 '13 at 11:40

1 Answers1

0

Try adding a javascript callback so you know when the web view contents have actually loaded: Javascript in UIWebView callback to C/Objective-C

Community
  • 1
  • 1
Wain
  • 118,658
  • 15
  • 128
  • 151