3

shouldStartLoadWithRequest:navigationTypewebViewDidStartLoadのメソッドがUIWebview一度呼び出されますが、その後はactivityIndicator回転し続け ( で始まりますwebViewDidStartLoad)、デリゲート メソッドwebViewDidFinishLoaddidFailLoadWithError呼び出されるメソッドはありません。これは、IOS 6 のみの問題です。

4

1 に答える 1

1

これは、iOS 5 および 6 で機能しています。Interface Builder でコンセントを接続していることを確認してください。おそらく、何らかのチェックを行って、インターネット アクセスが利用可能かどうかを確認する必要があります。私は Apple Reachability クラスでそれをやっています:

ヘッダ:

#import <UIKit/UIKit.h>
@interface HelpWebViewController : UIViewController <UIWebViewDelegate>
{
    IBOutlet UIWebView *webView;
    IBOutlet UIActivityIndicatorView *activityIndicator;
}

@property (nonatomic, strong) UIWebView *webView;
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, strong) NSString *webHelpURLString;

- (void)webViewDidStartLoad:(UIWebView *)webView; //a web view starts loading
- (void)webViewDidFinishLoad:(UIWebView *)webView;//web view finishes loading
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error; //web view failed to load

@end

実装ファイル:

 #import "HelpWebViewController.h"
    #import "Reachability.h" // Needs System Configuration Framework

    @interface HelpWebViewController ()

    @end

    @implementation HelpWebViewController

    @synthesize webView = ivWebView;
    @synthesize activityIndicator = ivActivityIndicator;
    @synthesize webHelpURLString = ivWebHelpURLString;

    -(BOOL)reachable {
        Reachability *r = [Reachability reachabilityWithHostName:@"apple.com"];
        NetworkStatus internetStatus = [r currentReachabilityStatus];
        if(internetStatus == NotReachable) {
            return NO;
        }
        return YES;
    }

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];    

        NSURL *webHelpURL = [NSURL URLWithString:@"support.apple.com"];
        NSURLRequest *myrequest = [NSURLRequest requestWithURL:webHelpURL];
        [self.webView loadRequest:myrequest];
        self.webView.scalesPageToFit = YES;

        if ([self reachable]) {
            NSLog(@"Reachable");
        }
        else {
            NSLog(@"Not Reachable");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"cantOpenWebPageAlertTitle", @"Cannot Open Page - UIAlert can't open web page")
                                                            message:NSLocalizedString(@"cantOpenWebPageAlertMessage", @"The page cannot be opened because you're not connected to the Internet.")
                                                           delegate:nil
                                                  cancelButtonTitle:NSLocalizedString(@"cantOpenWebPageAlertOKButton", @"OK - accept alert")
                                                  otherButtonTitles:nil];
            [alert show];
            alert = nil;
        }
    }

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

       [self.activityIndicator startAnimating];
 }

    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        [self.activityIndicator stopAnimating];
    }

    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
    {
        [self.activityIndicator stopAnimating];
    }

    @end
于 2012-12-16T16:49:24.640 に答える