6

There are a few question about this, which has a solution regarding the script embedded in html string. Not in my case.

I have a ios5/6 app. I have tryed to put the loading code into initWithNibName bad idea, viewDidLoad is deprecated , so viewWillAppear left.

- (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 flashing. It appears the UIViewContoller, with a white webView than after 1-2 seconds it is displayed the html. The HTML has some texts, but has base64 encoded images too, sometimes it is around 3Mb even 5MB content. No javascript is here, just inline CSS ( no external file ), text and base 64 encoded images.

I could pre-load into detailHtml the text, but I think the displaying takes more time.

Is that possible to do not display the ViewController, until the webView hasn't finished loading the html ? - some callback?

Any suggestions?

6
  • 1
    That would take little bit time to load the HTML string.But if everything works fine the why don't you put UIActivityIndicator so that would keep user engaged with the app.Even much better than keeping it blank. Commented Oct 8, 2012 at 12:45
  • @AjaySharma and when to stop the indicator? :) just asked for a callback :)
    – user529543
    Commented Oct 8, 2012 at 12:47
  • 1
    there is delegate method use this : - (void)webViewDidFinishLoad:(UIWebView *)webView.And stop your indicator over here. Commented Oct 8, 2012 at 12:51
  • @AjaySharma pls add your comments as answer, to be accepted and upvoted!
    – user529543
    Commented Oct 8, 2012 at 12:54
  • Thanks... I liked your favour ;) Commented Oct 8, 2012 at 16:05

1 Answer 1

5

That would take little bit time to load the HTML string default.But if everything works fine the why don't you put UIActivityIndicator so that would keep user engaged with the app.Even much better than keeping it blank

Here is one the delegate method of UIWebView :

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{
//And stop your indicator over here
   [indicator stopAnimating];
}
2
  • if really does't want the user the white thing I hope i can call a callback from the calling UIViewController to this and only than pop it, for now it is ok, thanks
    – user529543
    Commented Oct 8, 2012 at 16:13
  • Yes you are right bro.. but this is in general who don't want his view to be popped up & loading on the same screen, at that time, this delegate method would be really helpful. Commented Oct 8, 2012 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.