views:

451

answers:

2

I am trying to manage the activity indicator from my App Delegate, that way any of my views can put the indicator up. So, I am adding it as a subview to 'window' and start/stop as follows:

- (void)didStartActivity
{
    if( activityIndicator == nil ) {
        activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        activityIndicator.hidesWhenStopped = YES;
        activityIndicator.center = window.center;
        activityIndicator.transform = CGAffineTransformScale(CGAffineTransformIdentity, 6.0, 6.0);
    }
    NSLog(@"%s: starting the activityIndicator", __FUNCTION__);
    [window addSubview:activityIndicator];
    [activityIndicator startAnimating];
}

I see the log messages, so I know the code is being invoked. The indicator is at the center and 6x the default size. However, the stopAnimating isn't stopping. The only thing I can conclude is that it needs to run in the present view controller.

- (void)didStopActivity
{
    NSLog(@"%s: stopping the activityIndicator", __FUNCTION__);
    [activityIndicator stopAnimating];
    [activityIndicator removeFromSuperview];
}
A: 

check if your activityIndicator isn't nil:

NSLog(@"activityIndicator: %@", activityIndicator);
Eimantas
No, its non-nil as indicated by the log. Good idea -- do you think it has anything to do with it being created and managed in the app delegate?2010-01-30 13:07:46.073 MyApp[35463:4803] -[MyAppDelegate didStopActivity]: stopping the activityIndicator <UIActivityIndicatorView: 0x3b26e90; frame = (49 129; 222 222); transform = [6, 0, 0, 6, 0, 0]; animations = { contents=<CAKeyframeAnimation: 0x3b28750>; }; layer = <CALayer: 0x3b271a0>>
mobibob
A: 

OK. I did my experiment and sure enough, it worked flawlessly when I added the activity indicator as a subview of viewcontroller's view. However, when I then used that new simpleton project to try it as a subview to window it also worked. Obviously a bug in my code and it needs more inspection.

I will award both Eimantas with the answer as the debug notion was helpful in my solution.

mobibob