8

如何CLASS METHOD在主线程上调用 a ?就像是:

[SomeClass performSelectorOnMainThread:staticMethod withObject:nil];

请不要告诉我创建一个常规方法来调用此类方法。那将是一个明显的解决方案,但并不干净。

谢谢

4

2 回答 2

30
[SomeClass performSelectorOnMainThread:staticMethod withObject:nil waitUntilDone:NO];

是的,performSelectorOnMainThread:withObject:waitUntilDone:不是类方法。

是的,它是一个实例方法NSObject

是的,所有 Class 对象都是NSObject. (我不是在开玩笑!


你也可以这样做:

dispatch_async(dispatch_get_main_queue(), ^{
  [SomeClass doClassyThingWithObject:object1 andDiddleyDoo:foo];
});
于 2011-04-12T22:44:50.583 回答
2

怎么样:

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:[SomeClass class] selector:@selector(SomeClass) object:nil];
[[NSOperationQueue mainQueue] addOperation:operation];
于 2012-07-17T11:26:26.697 回答