2

我正在尝试使用 UIWebView 连接到 wikiTravel 页面。这是我的代码:

NSURL *url = [NSURL URLWithString:@"http://wikitravel.org/en/Beijing"];

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[wikiWebView loadRequest:requestObj];

如果我将北京更改为康沃尔,它会很好地显示所有信息。如果我将北京更改为蒙特利尔,它只会加载 wikitravel 徽标和两个按钮,但确实会调用webViewDidFinishLoad. 但是对于北京,它只是加载和加载并且不显示任何内容。

每当调用 UIWebView 方法时,我都会打印到控制台,这是输出:

2012-06-11 15:11:50.904 ExtraFeatures3[893:307] WEB VIEW DID START LOAD.
2012-06-11 15:11:57.607 ExtraFeatures3[893:307] WEB VIEW FAILED TO LOAD: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x19be10 {NSErrorFailingURLKey=http://wikitravel.org/en/Beijing, NSErrorFailingURLStringKey=http://wikitravel.org/en/Beijing}
2012-06-11 15:11:57.619 ExtraFeatures3[893:307] WEB VIEW DID START LOAD.
2012-06-11 15:11:59.523 ExtraFeatures3[893:307] WEB VIEW FAILED TO LOAD: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1a3190 {NSErrorFailingURLKey=http://wikitravel.org/en/Beijing, NSErrorFailingURLStringKey=http://wikitravel.org/en/Beijing}
2012-06-11 15:11:59.534 ExtraFeatures3[893:307] WEB VIEW DID START LOAD.
2012-06-11 15:12:00.875 ExtraFeatures3[893:307] WEB VIEW FAILED TO LOAD: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1a6e00 {NSErrorFailingURLKey=http://wikitravel.org/en/Beijing, NSErrorFailingURLStringKey=http://wikitravel.org/en/Beijing}

而且它只是继续前进和前进……我不知道该怎么办。

编辑:我所有的搜索都让我找到了以下解决方法,我已经尝试过但没有开始工作:

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    if([error code] == NSURLErrorCancelled)
    {
        return;
    }

}

任何帮助将不胜感激!

谢谢!

4

2 回答 2

3

根据这个网站:https ://discussions.apple.com/thread/1727260?start=0&tstart=0

这是解决方法:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
 NSLog(@"Error %i", error.code);
 if (error.code == NSURLErrorCancelled) return; // this is Error -999
 // error handling for "real" errors here
}
于 2012-06-11T19:40:34.303 回答
1

而不是尝试你的网址,首先尝试

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

你能加载吗?

于 2012-06-12T06:22:50.073 回答