I usually use NSTimer, which will call my spinner method, which I start right before starting to do the hard work (work that usually blocks the main thread).
NSTimer is called and my spinner method is called. When the main work is finished, I will turn off the counter.
Code for this:
IBOutlet UIActiviyIndicatorView *loginIndicator; { ... [loginIndicator startAnimating]; [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(executeAuthenticationRequest) userInfo:nil repeats:NO]; ... } - (void) executeAuthenticationRequest { sleep(3); [loginIndicator stopAnimating]; ... }
You can also do:
IBOutlet NSProgressIndicator *pIndicator;
Start:
[pIndicator startAnimation:self]; [pIndicator setHidden:NO];
And Stop:
[pIndicator stopAnimation:self]; [pIndicator setHidden:YES];
mr-sk source share