uiwebviewdelegate not called from non-visible uiwebview

情到浓时终转凉″ 提交于 2019-12-11 11:08:09

问题


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:


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.



来源:https://stackoverflow.com/questions/10166399/uiwebviewdelegate-not-called-from-non-visible-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!