2

有効なURLを読み込もうとすると、次のメッセージが表示され、Webページが表示されません。

delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:)10秒待っても戻れませんでした。メイン実行ループモード:kCFRunLoopDefaultMode

誰かが親切に私を助けてくれますか?

使用:iOS4.x上のiPad2

コメント:iOS5.xでは問題ないようです

使用したコード:

    newsWebView=[[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height-50.0-adHeight)];
    newsWebView.dataDetectorTypes = UIDataDetectorTypeAll;
    newsWebView.backgroundColor=[UIColor blackColor];
    [newsWebView setScalesPageToFit:YES];
    [self.view addSubview:newsWebView];
    newsWebView.delegate=self;
    [self webViewLoadRequest];


- (void)webViewLoadRequest 
{
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [newsWebView loadRequest:requestObj];
}

//Delegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    return YES;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {  

}

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{
    CGFloat scale=newsWebView.contentScaleFactor;
    NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = %f;",scale];
    [newsWebView stringByEvaluatingJavaScriptFromString:jsCommand];

    [rightButton setEnabled:YES];

    if(titleStatus==1){
        self.title=[newsWebView stringByEvaluatingJavaScriptFromString:@"document.title"];
    }
} 

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    if (error.code == 101) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Cannot Open Page"
                                                        message:[error localizedDescription] delegate:nil
                                              cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [alert show];
        [alert release];

    } else if (error.code == -1003) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Cannot Open Page"
                                                        message:@"Server cannot be found." delegate:nil
                                              cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [alert show];
        [alert release];

    } else if (error.code == -1009) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Cannot Open Page"
                                                        message:@"No network connection." delegate:nil
                                              cancelButtonTitle:@"Dismiss"      otherButtonTitles:nil];
        [alert show];
        [alert release];

    } else if (error.code == -999) {
        // user probably stopped the web loading
    } else {
        NSLog(@"Error: %@", error.description);
    }
}
4

2 に答える 2

0

WebViewsデリゲートをどこにも設定していない..コードでWebViewを作成している場合は、そのデリゲートを設定して実装する必要があります..

WebView の設定中に次の行を追加します

     [newsWebViewNews setDelegate:self];

UIWebViewDelegate< > をクラス ヘッダー ファイルに実装します。

于 2012-07-11T02:11:07.850 に答える
0

これを試すための例を作成しましたhttps://www.dropbox.com/s/lch00t0vjrydg77/ActivityIndi ​​cator.zip

于 2013-09-17T13:51:49.163 に答える