setHidden:有不必要的延迟



我现在有一个非常奇怪的bug。

一个方法被调用,该方法应该通过停止UIActivityIndicatorView来隐藏它(当启用停止时自动隐藏)和UIImageView称为badIndicator

作为替换,它应该显示另一个UIImageView称为goodIndicator

[goodIndicator setHidden:NO];
[badIndicator setHidden:YES];
[refreshIndicator stopAnimating];
NSLog(@"statussetting good should be completed");

控制台立即打印以下内容,但是需要大约三秒钟才能在屏幕上显示更改。

2013-05-31 20:24:57.835 app name[5948:1603] statussetting good should be completed

我试过调用对象和父视图上的setNeedsDisplay方法,也用alpha替换隐藏。还是有同样的问题

听起来像是从后台线程调用的。所有与UIKit的交互都需要在主线程中进行。尝试使用:

dispatch_async(dispatch_get_main_queue(), ^{
    [goodIndicator setHidden:NO];
    [badIndicator setHidden:YES];
    [refreshIndicator stopAnimating];
    NSLog(@"statussetting good should be completed");
});

你需要在主线程中调用这个方法。尝试使用:

-(void)hideControls { 
    [goodIndicator setHidden:NO]; 
    [badIndicator setHidden:YES]; 
    [refreshIndicator stopAnimating]; 
    NSLog(@"statussetting good should be completed"); 
}

最新更新