开发者

Identify thread of current scope

How does one determine the thread a given function call is running on?

I want to make sure a method is called on the main thread in order to update some UI elements.

Can I for example do something like this?

- (void) myMethod {
    if (<current thread is not main thread>) {
        [self performSelectorOnMainThread: @selector(myMethod) withO开发者_如何学JAVAbject: nil waitUntilDone: NO];
    } else {
        // my code here
    }
}


Check out [NSThread isMainThread].

http://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html#//apple_ref/occ/clm/NSThread/isMainThread

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜