如何使用performSelector:

All*_*len 0 iphone xcode objective-c

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

ken*_*ytm 5

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

[object performSelectorInBackground:@selector(method:) withObject:foo];
Run Code Online (Sandbox Code Playgroud)

如果您要创建一个线程,请使用

NSThread* thread = [[NSThread alloc] init];
[object performSelector:@selector(method:)
               onThread:thread
             withObject:foo
          waitUntilDone:YES];
[thread release];
Run Code Online (Sandbox Code Playgroud)

  • 嗨Kenny,你需要在目标线程中运行一个运行循环,以便处理`performSelector:`输入源.所以我认为你的代码不起作用...... (3认同)