如何使用performSelector:

时间:2010-05-13 12:14:28

标签: iphone objective-c xcode

如何使用performSelector:onThread:withObject:waitUntilDone:?这里在onthread我必须使用其他线程而不是主线程。如何创建其他线程?给我一些示例代码。

1 个答案:

答案 0 :(得分:5)

除非您有一个要管理的线程池,否则使用-performSelectorInBackground:…更容易:

[object performSelectorInBackground:@selector(method:) withObject:foo];

如果您要创建一个帖子,请使用

NSThread* thread = [[NSThread alloc] init];
[object performSelector:@selector(method:)
               onThread:thread
             withObject:foo
          waitUntilDone:YES];
[thread release];
相关问题