UIWebView does not initially load certain URLs

一个人想着一个人 提交于 2019-12-10 18:42:40

问题


Having such a bizarre issue with the UIWebView and I haven't been able to find a solution online. I have an iPad app that has a web view in it. Upon first install and run of the app, I try to load an education website. The web view just hangs and times out. I kill the app, I run it again, and it loads just fine. This one works fine which is also part of the education website. I'm pulling my hair out!

Some code:

-(void)viewDidAppear:(BOOL)animated
{
   NSURL *websiteUrl = [NSURL URLWithString:@"http://my.tac.edu.au"];
   NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL: websiteUrl];
   [self.webView loadRequest:urlRequest];
}

Works fine with www.tac.edu.au. I don't know what it is about that URL that makes it hang only when the app is first installed. You stop it, run it again (without uninstalling) and it comes up just fine. Any help would be appreciated.


回答1:


:)

instead of view did appear , write the code in view will appear

-(void)viewWillAppear:(BOOL)animated
{
   NSURL *websiteUrl = [NSURL URLWithString:@"http://my.tac.edu.au"];
   NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL: websiteUrl];
   [self.webView loadRequest:urlRequest];
   self.webview.delegate = self;
}

- (void)webViewDidStartLoad:(UIWebView *)webView{
  //Start Activity Indicator
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{

   //End activity indicator
}


来源:https://stackoverflow.com/questions/21745969/uiwebview-does-not-initially-load-certain-urls

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