I am calling a method from two threads and thought I try 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With