[英]Objective C - Calling a class method on the main thread?
如何在主線程上調用CLASS METHOD
? 就像是:
[SomeClass performSelectorOnMainThread:staticMethod withObject:nil];
請不要告訴我創建一個常規方法來調用這個類方法。 這將是一個明顯的解決方案,但不是很干凈。
謝謝
[SomeClass performSelectorOnMainThread:staticMethod withObject:nil waitUntilDone:NO];
是的, performSelectorOnMainThread:withObject:waitUntilDone:
不是類方法。
是的,它是NSObject
上的一個實例方法。
是的,所有Class對象都是NSObject
實例。 ( 我不是在開玩笑! )
你也可以這樣做:
dispatch_async(dispatch_get_main_queue(), ^{
[SomeClass doClassyThingWithObject:object1 andDiddleyDoo:foo];
});
怎么樣:
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:[SomeClass class] selector:@selector(SomeClass) object:nil];
[[NSOperationQueue mainQueue] addOperation:operation];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.