views:

174

answers:

3

Hello frends,

I have a problem regarding UIActivityIndicator. I applied "[spinner startAnimating]" at the IBAction on a button and then doing some process. After the process activityindicator should be stopped and then navigate to another view. But the activity indicator does not appear. When I remove the line "[spinner stopAnimating]" then the indicator appears but not at the instant button is pressed. It appears just before the other view loads, and apparently does not appear, I mean it does not appear but if we see very carefully then only it appears for an instant.

Thanx in advance for any answer.

A: 

The animation will not start until your code returns control to the run loop. If your processing task blocks the main thread, the no UI updates will take place until it is finished. You should do your processing asynchronously (e.g. by starting an NSOperation).

Ole Begemann
+1  A: 

Ole is pretty much correct, but there is a trick of you don't mind synchronous processing (often that it why you want to display the activity indicator in the first place).

First move your code that you want to process while the spinner is up to its own method. Then do [spinner startAnimating]; [self performSelector:@selector(methodname) withObject:nil afterDelay:0];

The afterDelay:0 means on the next time through the run loop. That way the spinner gets started.

Andiih
Oh and Ole is also right when he suggests you should go back through your previous questions and accept (click the tick mark) the correct ones!
Andiih
Actually my code is something like this: -(IBAction)buttonPressed:(id)sender {[spinner startAnimating];if(condition) {[self presentModalViewController:aView animated:yes];[spinner stopAnimating];}}
Jack
so move your if, self present and spinner stop to a method and call that with performSelector:WithObject:afterDelay:0
Andiih
A: 

you should run in perform selector .

for ex:

[self performSelector:@selector(animation) withObject:nil afterDelay:0]

-(void)animation

{

NSAutoreleasepool *pool = [[NSAutorepleasepool alloc]init];

[indicatorView startAnimating];

[pool release];

}

maddy