我正在使用 NetworkActivityIndi​​cator 来显示我的应用程序正在执行一些工作。当我在模拟器中运行应用程序时,它显示了我想要的方式 - 基本上一直旋转,直到选定的选项卡从服务器加载数据 - 但当我将应用程序放到手机上时,我只得到了瞬间在旋转器消失之前。通常仅在视图出现在屏幕上之前旋转。

有想法吗?

编辑:问题可能与我使用 TabBar 的事实有关......在模拟器中,当加载屏幕/选项卡 2 时,ActivityIndi​​cator 将在屏幕/选项卡 1 上旋转。在手机上,我只在屏幕 2 最终出现后的一瞬间看到了 ActivityIndi​​cator。

-(void)viewDidLoad {

// call to spinTheSpinner
[NSThread detachNewThreadSelector:@selector(spinTheSpinner) toTarget:self withObject:nil];

// method to Get the Data from the Server
[self getDataFromServer];

}

-(void)spinTheSpinner {
    NSLog(@"Spin The Spinner");
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [self performSelectorOnMainThread:@selector(doneSpinning) withObject:nil waitUntilDone:YES];

    [pool release]; 
}

-(void)doneSpinning {
    NSLog(@"done spinning");
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

-(void)getDataFromServer {
    // does a bunch of stuff to retrieve and display data
}
有帮助吗?

解决方案

你在这里打开旋转器......

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

但你立即将其关闭......

[self performSelectorOnMainThread:@selector(doneSpinning) …];

当然不会显示。我很惊讶它在模拟器中显示。

-doneSpinning 应该调用方法 -getDataFromServer 已经完成,或者只是做

UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
[self getDataFromServer]; // assumes it is blocking.
app.networkActivityIndicatorVisible = NO;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top