cocoa 创建线程

Threading

1. Create the new thread:
[NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil];
2. 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)? UseperformSelectorOnMainThread.
[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false];

posted on 2011-07-15 15:39  风乔  阅读(213)  评论(0编辑  收藏  举报

导航