用类方法NSThread?

Jer*_*ckx 4 cocoa nsthread

是否可以在单独的线程中运行类方法(以'+'开头)?通常我会像[myClass myController];我尝试的那样调用方法[NSThread detachNewThreadSelector:myController toTarget:myClass withObject:nil];但没有成功.

Nic*_*ore 10

是的,你只需要制作目标[myClass class]而不是myClass.你也忘了@selector()在选择器名称周围使用.所以你要:

[NSThread detachNewThreadSelector:@selector(myController) toTarget:[myClass class] withObject:nil];