views:

50

answers:

2

hi, 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 |
        UIViewAutoresizingFlexibleRightMargin |
        UIViewAutoresizingFlexibleTopMargin |
        UIViewAutoresizingFlexibleBottomMargin);

  UIBarButtonItem *loadingView = [[UIBarButtonItem alloc]           initWithCustomView:activityIndicator];
        loadingView.target = newController;

newController.navigationItem.rightBarButtonItem = loadingView;

Thks in advance! :)

A: 

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];
}
jkilbride
ya this works thks, but its in the status bar, i would like it to be at the top right bar
Stefan
hey got it, thks!!
Stefan
no problem, glad to help. Can you accept the answer if it solved the question. Thanks!
jkilbride
A: 

you have to do [activityIndicator stopAnimating] when you want it to stop...

Thomas Clayson
i think i miss this, but i can't figure out where to place the code. the above code is in didSelectRowAtIndexPath
Stefan
thks i got it!!
Stefan