1
votes

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.

1

1 Answers

0
votes

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.