开发者

Is circular method calling allowed?

I am calling a method from two threads and thought I tr开发者_如何学JAVAy this:

- (void)hideEnterButton
{
    if ([NSThread isMainThread])
    {
        enterButton.hidden = YES;
    }
    else
    {
        [self performSelectorOnMainThread:@selector(hideEnterButton) withObject:nil waitUntilDone:NO];
    }
}

Reason for this is that I understand that all GUI handling must be done on the main thread. Will this work?


The proper term is recursive, not circular and yes, it's perfectly fine to do this.


Yes, this is completely valid. I have used this exact method before, and it works very well. The only problem is, any code using this cannot assume that the button is hidden after it returns because it doesn't wait for the call to finish. If that won't be a problem, use it as is. If it will, simply pass YES for waitUntilDone: instead.


Yes. This is a common pattern.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜