activity indicator not stopping
for my following code, why is my activity indicator for my webview not stoping?
//this part ok
NSURL *theURL = [NSURL URLWithString: Link];
NSURLRequest *request = [NSURLRequest requestWithURL: theURL];
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,300,300)];
webView.scalesPageToFit = YES;
[webView setDelegate: self];
[webView loadRequest: request];
/*this part ok*/
UIViewController *newController = [[UIViewController alloc] init];
newController.view = webView;
[self.navigationController pushViewController:newController animated:YES ];
//activity indicatior not stoping!
CGRect frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[activityIndicator startAnimating];
[activityIndicator sizeToFit];
activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresiz开发者_如何学GoingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
UIBarButtonItem *loadingView = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
loadingView.target = newController;
newController.navigationItem.rightBarButtonItem = loadingView;
Thks in advance! :)
you have to do [activityIndicator stopAnimating]
when you want it to stop...
You need to implement the UIWebViewDelegate methods:
- (void)webViewDidStartLoad:(UIWebView *)webView {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[activityIndicator stopAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[activityIndicator stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[activityIndicator stopAnimating];
}
精彩评论