Proper way to show/hide animating Activity Indicator

There are scenarios when one does some heavy weight fetching of data from an external database thats time consuming. During the fetching, we want to give appropriate feedback to user that something is being done. Thats when Activity Indicator (UIActivityIndicator) object comes in handy. Its a spinner that shows and spins and then stops animating and disappears when the process is finished.

A point to be noted is that one should always start Spinner in a separate thread.

Wrong (works only sometimes):

[activityindicator startanimating];
//Some code
[activityindicator stopanimating];


[NSThread detachNewThreadSelector:@selector(threadStartAnimating: ) toTarget:self withObject:nil];
// Some code  
[spinner stopAnimating];
[self.navigationcontroller pushviewcontroller:viewcontroller animated:YES]; 

-(void)threadStartAnimating: (id)data
[spinner startAnimating];

  1. No comments yet.

  1. No trackbacks yet.