开发者

activity indicator not stopping

开发者 https://www.devze.com 2023-01-13 10:01 出处:网络
for my following code, why is my activity indicator for my webview not stoping? //this part ok NSURL *theURL = [NSURL URLWithString: Link];

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];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号