gpt4 book ai didi

iPhone - UIWebView - 在页面加载之前单击 URL 会使 didFailLoadWithError 抛出错误

转载 作者:行者123 更新时间:2023-12-03 19:37:20 25 4
gpt4 key购买 nike

在我的 iPhone 应用程序中,我在 webview 中显示一个网页。我实现委托(delegate)方法如下:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error loading the requested URL" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}

当我打开一个 URL 并加载半页时,我会立即单击网页中的其他链接。此时,该委托(delegate)方法也被调用。当网页加载一半并点击 URL 链接时,如何防止调用委​​托方法。

或者其他一些解决方案可以是在单击某个 URL 时调用 stopLoading。我怎样才能做到这一点?

最佳答案

错误代码NSURLErrorCancelled通知您URLLoadingSystem“已停止加载”。例如,当用户单击仅加载了一半的页面中的链接时,就会发生这种情况...URLLoadingSystem 会停止它,因此您不需要这样做。

- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
{
// If the URLLoadingSystem cancelled the load don't show anything.
if ( [error code] == NSURLErrorCancelled )
{
//...this is called when the load is cancelled...
}
else
{
//...handle the error and show the alert ...
}
}

关于iPhone - UIWebView - 在页面加载之前单击 URL 会使 didFailLoadWithError 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4680610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com