I am running creating an iPhone application which performs a costly operation and I wanted to create an activityIndicator to let the user know the application has not frozen
I just found someone asking a very similar question with a good answer on the apple iPhone forums. https://devforums.apple.com/message/24220#24220 #Note: you have to have an appleID to view it.
Essentially, yes, you do need to start your process running in a different thread, but its quite easy to do (as paraphrased from user 'eskimo1')
- (IBAction)syncOnThreadAction:(id)sender
{
[self willStartJob];
id myObject = [MyObjectClass createNewObject];
[self performSelectorInBackground:
@selector(inThreadStartDoJob:)
withObject:myObject
];
}
- (void)inThreadStartDoJob:(id)theJobToDo
{
NSAutoreleasePool * pool;
NSString * status;
pool = [[NSAutoreleasePool alloc] init];
assert(pool != nil);
status = [theJobToDo countGrainsOfSandOnBeach];
[self performSelectorOnMainThread:
@selector(didStopJobWithStatus:)
withObject:status
waitUntilDone:NO
];
[pool drain];
}
where -willStartJob
and -didStopJobWithStatus
are my own methods that: