线程(重要基础知识)
1. 创建一个新的线程:
[NSThread detachNewThreadSelector:@selector(myMethod)
2. 创建线程所调用的方法:
- (void)myMethod {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
*** code that should be run in the new thread goes here *** [pool release];
}
假如我们需要在线程里面调用主线程的方法函数,就可以用
performSelectorOnMainThread来实现:
[self performSelectorOnMainThread:@selector(myMethod)
waitUntilDone: false ];
除注明原创外,一般为转载,好文大家分享。
浙公网安备 33010602011771号