Simple threading: performSelectorInBackground Use
I saw somewhere how to animate an UIActivityIndicator while processing a time consuming stuff. I tried myself, but it keeps crashing both on simulator and device. Does anyone see what I am doing wrong?
- (IBAction)doStuff:(id)sender {
[self performSelectorInBackground:@selector(doInBackground:) withObject:nil];
}
- (void)doInBackground {
NSAutoreleasePool * pool;
pool = [[NSAutoreleasePool alloc] init];
[self doLengthyProcessing];
[self performSelectorOnMainThread:@selector(animateIndicator:) withObject:nil waitUntilDone:NO];
[pool drain];
}
- (void)animateIndicator {
[self.activityIndicator startAnimating];
}
- (void)doLengthyProcessing {
// ...
}
iMac, Mac OS X (10.5.6)