views:

1208

answers:

2

I want to show UIActivityIndicatorView on my iphone when it changing the view. I have written the following code:

- (void)viewDidLoad 
{

  spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  [spinner setCenter:CGPointMake(320/2.0, 460/2.0)]; // I do this because I'm in landscape mode
  [self.view addSubview:spinner];
}

and on button's click event I want to change the view and in between that time I want to show that indicatorView So, I write

-(IBAction)buttonClick:(id)sender
{

    [spinner startAnimating];
    ViewController *lController = [[ViewController alloc] initWithNibName: @"View" bundle:nil];
    self.viewController = lController;
    [lController release];
    //
    [[self mainController] dismissModalViewControllerAnimated:YES];
    [lViewController.view removeFromSuperview];
    [self.view addSubview: lController.view];
    [spinner stopAnimating];
 }

It is not displaying the Indicator, So plz tell me where I am wrong?

A: 

In buttonClick it looks like you're adding the lController.view "on top" of the spinner (which was added earlier in viewDidLoad). It's hard to tell from your snippet what's going on with the modal dismissal so let's assume that's not the culprit.

You could try either calling [self.view bringSubviewToFront:spinner] after adding the new subview or else [self.view insertSubview:lController.view belowSubview:spinner] to put your view underneath the spinner. You may also want to set the hidesWhenStopped property on the spinner to YES so it automatically hides when you stop it.

Another thing to keep in mind is that loading and switching views may not actually take that long, so the spinner may not appear if things happen too fast.

Ramin
A: 

Can anyone tell me how long it takes to load the UIActivityIndicatorView to load on the UI?

In my application, on button click, I start animating the activity indicator, then i am doing some tasks, like calling web service, inserting data in local db, etc. and at the end i m stoping the animation.

now, if i comment everything after start animation (including stop animation), the indicator is displayed on UI. as soon as i uncomment the code (not stop animation), the indicator is not displayed.

i m not able to guess what's going wrong in the code.....

Please help.

Pravara