3

我看到 Apple 的 UIWebViewDelegate 中没有记录这种行为:

如果我向委托函数返回 NO

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

立即调用此函数并显示错误 101(无法加载此 URL。)。

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {

既然我明确取消了请求,那么调用 didFailLoadWithError 是否正常?

4

2 回答 2

2

更新:如果您手动取消连接,UIWebView 将不会调用 didFailLoadWithError。

我已经通过测试验证了这一点。didFailLoadWithError 的原因是与 UIWebView 完全无关的其他事情。

于 2011-08-15T03:17:43.453 回答
0

你应该总是返回noshouldStartLoadWithRequest,返回YESweb view 是否应该开始加载内容;否则,

如果您的连接出现错误 101 (net::ERR_CONNECTION_RESET): Unknown 错误,那么您可能遇到以下问题:

You are trying to connect to the internet but the pages won’t load.
You are trying to refresh/reload the page so many times but to no avail.
You can see a lot of weird stuff all over the page. (links and images are unaligned.)
When the page doesn’t load, you can see the phrase “Error 101 (net::ERR_CONNECTION_RESET): Unknown error”.

您应该始终将请求处理给您的委托并返回 NO 然后在收到的来自 NSURLConnection 的响应调用中取消连接,如果一切正常(检查响应)再次在 web 视图中加载 urlrequest。再次加载 urlrequest 时,请确保在上述调用中返回 YES。或者您可以使用同步或异步方法来处理它。

于 2011-08-12T12:40:31.207 回答