UIActivity指示器在iPhone 4(视网膜)上不工作

UIActivity指示器在iPhone 4(视网膜)上不工作,iphone,ios-simulator,uiactivityindicatorview,retina-display,Iphone,Ios Simulator,Uiactivityindicatorview,Retina Display,我有一个UIActivityIndicator,它在iPhone 3G模拟器/设备中运行良好,但在iPhone 4(视网膜)的模拟器/设备上不起作用。我想说的是,它的背景是黑色的。我以前也遇到过类似的问题。通过将指示器样式更改为UIActivityIndicatorViewStyleWhiteLarge,并为背景提供对比色(我选择黑色),解决了这个问题。问题实际上是它不可见。UIActivityIndicator不会立即显示 如果您有这样的代码: //(pseudo-code) //Create

我有一个
UIActivityIndicator
,它在iPhone 3G模拟器/设备中运行良好,但在iPhone 4(视网膜)的模拟器/设备上不起作用。我想说的是,它的背景是黑色的。

我以前也遇到过类似的问题。通过将指示器样式更改为
UIActivityIndicatorViewStyleWhiteLarge
,并为背景提供对比色(我选择黑色),解决了这个问题。问题实际上是它不可见。

UIActivityIndicator不会立即显示

如果您有这样的代码:

//(pseudo-code)
//Create UIActivityIndicator
//show UIActivityIndicator
//do some other stuff expecting view to show
UIActivityIndicator不会显示,因为UIActivityIndicator只会在程序的下一个运行循环中显示

你可以通过

{
    //create UIActivityIndicator
    //show UIActivityIndicator
    [self performSelector:@selector(doOtherStuff) withObject:nil afterDelay:0];
}

-(void)doOtherStuff {
    //do stuff 
}
performSelector意味着doOtherStuff将在下一个运行循环中执行,此时UIActivityIndicator将显示


您还必须将其作为子视图添加到要在其中显示的视图中。

可能您显示的微调器来自非主线程的线程?您可以尝试此断言以确定是否在主线程上:

NSAssert([[NSThread currentThread] isMainThread],
    @"This should be run from the main thread.");
dispatch_async(dispatch_get_main_queue(), ^{
    // display the spinner
});
如果断言失败,您可以将调用分派到主线程:

NSAssert([[NSThread currentThread] isMainThread],
    @"This should be run from the main thread.");
dispatch_async(dispatch_get_main_queue(), ^{
    // display the spinner
});

无论如何,没有看到代码,我们都只是猜测。

请澄清“不工作”是什么意思。它是否显示不正确,没有显示在屏幕上等等。截图会很好。实际上,样式设置为UIActivityIndicatorViewStyleWhiteLarge,背景也是黑色的。实际上,我没有注意到它确实是灰色的,将其更改为白色,帮助了我,谢谢。将指示器更改为灰色也帮助了我,但我不太明白。即使是在白色背景下,指示器也应该是可见的(当然是在老式iPhone上),为什么它会隐藏在视网膜显示屏上?我试图将背景色设置为除白色以外的其他颜色,但大白色仍然不可见。我正在创建一个启动屏幕,并且它不会在后台运行。不管怎样,它在iphone3g和iPad上都能正常工作。