Sending loadRequest messages to UIWebView before c

2019-06-14 10:43发布

I have a webview as the detail view of a tableView navigation based app. There are "UP" and "DOWN" arrows on the navigationBar that the user can use to page through the different detail views.

Everything works fine as long as the user only clicks the "UP" or "Down" arrows once. But if the arrows are clicked multiple times and the loadRequest message is sent twice to the UIWebView, I get the error message "NSURLErrorDomain error -999" from my didFailLoadWithError method.

It seems like if a loadRequest is sent while the page is currently loading a view the error is sent. As long as the page is finished loading everything works fine.

I've tried a variety of solutions, all with the same result.

Thanks for the help!

2条回答
霸刀☆藐视天下
2楼-- · 2019-06-14 11:43

I had the same problem today - try also this approach:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  NSLog(@"didFail: %@ stillLoading:%@ error code:%i", [[webView request]URL], (webView.loading?@"NO":@"YES"), [error code]);
  if ([error code] != -999) {
    // Handle your other errors here
  }
}

Reference

查看更多
三岁会撩人
3楼-- · 2019-06-14 11:49

I solved the problem by calling:

[self.myWebView stopLoading];
myWebView.delegate = nil;

before reloading the new URL. Before I send the new loadRequest I call:

myWebView.delegate = self;
查看更多
登录 后发表回答