1

I am trying to avoid the blank white window that shows while a UIWebView loads content. Instead of putting a background on the UIWebView, I'd like to just put up a HUD on the current window and then push the new uiviewcontroller that contains the uiwebview when the content is loaded. Here's what I've done (code shortened for sanity's sake):

FirstView:

MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
myVC.parentController = self.navigationController;
UIView *myView = [myVC view];      // Force view to load

MyViewController:

- (void)viewDidLoad
{
  ...
  [myWebView setDelegate:self];
  [myWebView loadHTMLString:htmlString baseURL:baseURL];
  ...
 }


- (void) webViewDidFinishLoad:(UIWebView*) webView {
     [parentController pushViewController:self animated:YES];
}

OK, so viewDidLoad is getting called, but none of the uiwebviewdelegate methods are getting called. However, if I push the view controller

FirstView:

MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[self.navigationController myVC animated:YES];

Then all of the uiwebviewdelegate methods in MyViewController do get called.

I'm stuck.

Cezar
  • 55,636
  • 19
  • 86
  • 87
michael
  • 241
  • 1
  • 5
  • 12

1 Answers1

0

I don't know the specific requirements for your app, but it's usually a better practice to first push your view controller and then show the HUD on top of the new view controller while your content loads. You would add the HUD to the view controller's view in viewDidLoad, and remove the HUD in your webView's webViewDidFinishLoad callback method.

If you are not already doing so, make sure you are loading your web view's content in a background thread so as to not block the main UI thread while the content loads, otherwise it will appear to the user that your app has temporarily frozen.

jonkroll
  • 15,682
  • 4
  • 50
  • 43
  • What you're saying is what I was doing, but the problem I had was that when I pushed the view controller, it takes the uiwebview 0.5 to 4 seconds to load content and the user just sees a blank white window during that time. I could set a background image while the html content was loading, but I think it'd be better to just throw up a HUD over the first view until the content was loaded and then display the uiwebview... I think some interstitial image will be distracting for the 0.5 second scenarios. – michael Apr 15 '12 at 22:46
  • I agree that showing an HUD is the way to go, but I still think you're better off showing the HUD on the destination viewcontroller while you're loading the content after the segue happens. If you still want to show the HUD on your first viewcontroller then I would make your first viewcontroller responsible for requesting the htmlString and then when the response is received set the response string as a property on your destination viewcontroller before your push it onto your nav stack. – jonkroll Apr 15 '12 at 22:53
  • I think we're a bit off-track... or I may be missing something. My problem is that none of the uiwebviewdelegate methods are being called until after the destination viewcontroller is pushed. Once the uiwebview has the HTML, it still takes a few seconds for the uiwebview to load the links/images and I have a blank white screen in that time. I want to find out why the delegate methods aren't being invoked... or find some other way to wait until the uiwebview has loaded content before I show it. – michael Apr 16 '12 at 00:20