我正在开发的 iPad 应用程序有问题。我有以下代码:
CFTimeInterval startTime = CFAbsoluteTimeGetCurrent();
[self showSpinnerWithMessage:@"Loading settings..."]; // Shows a UIActivityIndicator on screen
dispatch_async(dispatch_get_global_queue(0, 0), ^
{
//Updating items on screen here
[label1 setText:@"Test1"];
[label2 setText:@"Test3"];
//...
CFTimeInterval difference = CFAbsoluteTimeGetCurrent() - startTime;
if (difference < MINIMUM_INDICATOR_SECONDS)
{
[NSThread sleepForTimeInterval:MINIMUM_INDICATOR_SECONDS - difference];
}
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self removeSpinner]; // Removes UIActivityIndicator from screen
});
};
问题是有时 UI 需要一段时间才能更新,并且在这些特定情况下,微调器 (UIActivityIndicator) 在 UI 实际更新之前就消失了。我意识到这是因为屏幕上的项目直到下一个运行循环才真正更新,所以我的问题是,如何让我的[self removeSpinner]
调用等到 UI 更新?