WebView loadHTMLString termination?

There are a few questions about this which has a solution regarding a script embedded in an html string. Not in my case.

I have an ios5 / 6 application. I tried putting the loading code in initWithNibName bad idea, viewDidLoad deprecated, so viewWillAppear remains.

 - (void) viewWillAppear:(BOOL)animated { NSString* detailHtml = [Storage getDetailHtml: -1];// get the last one //NSLog(@"detailHtml: %@", detailHtml); if(detailHtml == nil){ NSLog(@"Can't load the detail"); detailHtml = @"<html><body>Some text here</body></html>"; } [webView loadHTMLString:detailHtml baseURL:nil]; [super viewWillAppear:animated]; } 

The problem with this code is blinking. It looks like a UIViewContoller, with a white webView than html is displayed after 1-2 seconds. HTML has some texts, but also has base64 encoded images, sometimes it is about 3 MB, even 5 MB of content. There is no javascript, just embedded CSS (without an external file), text and base 64 encoded images.

I could preload the detailHtml text, but I think it takes longer to render.

Is it possible not to display the ViewController until the webView has finished loading the html? - some callback?

Any suggestions?

+4
source share
1 answer

It takes a little time to load the default HTML string. But if everything works fine, why don't you put the UIActivityIndicator so the user can use the application. Even much better than keeping it empty.

Here is one of the UIWebView delegate methods:

 - (void)webViewDidFinishLoad:(UIWebView *)webView { //And stop your indicator over here [indicator stopAnimating]; } 
+3
source

Source: https://habr.com/ru/post/1438405/


All Articles