skip to main |
skip to sidebar
iPhone SDK Tips & Tricks
- (void) startNewThread {
// this kicks off a new thread like bruce-lee
[self performSelectorOnMainThread:@selector(loading) withObject:nil waitUntilDone:NO];
[NSThread detachNewThreadSelector:@selector(doNewThreadStuff) toTarget:self withObject:nil];
}
- (void)loading
{
if(looping)
{
//do loading animation
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(loading) userInfo:nil repeats:NO];
}
}
- (void) doNewThreadStuff {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// this is where you do your stuffs that takes forever and 2 days and 3 minutes
// then when done, you call the following to get back on track
[self performSelectorOnMainThread:@selector(newThreadDone) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void) newThreadDone {
// yay we finished, now continue onwards and upwards. maybe sideways a bit too.
}