UIWebView上的UIActivityIndi​​cator开始在页面链接上旋转 - 不停止

时间:2015-07-08 02:19:42

标签: ios objective-c webview uiwebview

我在UIWebView上使用UIActivityIndi​​cator来指示页面加载,并且它工作正常。但是,在某些页面上,当我单击链接进一步向下导航页面时,指示器再次开始旋转并且不会停止。这只在页面正确加载后才会发生。

代码:

- (void)viewDidLoad {

[super viewDidLoad];

[self loadWebViewRequest];

self.back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backButton"] style:UIBarButtonItemStylePlain target:self action:@selector(backButton)];

self.forward = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forwardButton"] style:UIBarButtonItemStylePlain target:self action:@selector(forwardButton)];

self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:_forward, _back,   nil];

self.forward.enabled = NO;
self.back.enabled = NO; 

self.theBool = false;

self.webView.delegate = self;
}

-(void) backButton {
[self.webView goBack];
}

-(void) forwardButton {
[self.webView goForward]; 
}


-(void) webViewDidFinishLoad:(UIWebView *)webView {
if (self.webView.canGoForward)
    {
        self.forward.enabled = YES;
    }
else
    {
        self.forward.enabled = NO;
    }


if (self.webView.canGoBack)
    {
        self.back.enabled = YES;
    }
else
    {
        self.back.enabled = NO;
    }

self.refresh.enabled = YES;

[self.activityIndicator stopAnimating];
}

-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
self.refresh.enabled = NO;
[self.activityIndicator startAnimating];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Reference" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;

return YES;
}

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

[self.activityIndicator stopAnimating];
self.refresh.enabled = YES;
NSLog(@"Whoops"); 
}

-(void) loadWebViewRequest {
NSURL *url = [[NSURL alloc] initWithString:self.urlString];

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

[self.webView loadRequest:request];

}

由于

0 个答案:

没有答案