Create the new thread:
|
1 2 3 4 5 6 7 8 9 |
[NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil]; Create the method that is called by the new thread: - (void)myMethod { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; /*** code that should be run in the new thread goes here ***/ [pool release]; } |
What if you need to do something to the main thread from inside your new thread (for example, show a loading symbol)? Use performSelectorOnMainThread.
|
1 |
[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false]; |
Filed under: Box 2d • Cocoa • Cocos2d • iPad • iPhone • Objective C
Like this post? Subscribe to my RSS feed and get loads more!




Leave a Reply