NetworkActivityIndi​​cator 在 iPhone 和模拟器上的工作方式不一样?

发布于 2024-08-28 10:43:25 字数 1097 浏览 5 评论 0原文

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

有想法吗?

编辑:问题可能与我使用 TabBar 的事实有关...在模拟器中,当加载 Screen/Tab 2 时,ActivityIndi​​cator 将在 Screen/Tab 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
}

I am using the NetworkActivityIndicator to show that my App is doing some work. When I run the app in the simulator, it shows the way I want - basically spinning the entire time until the selected tab loads the data from the server - but when I put the app onto my phone, I only get a split-second of the spinner before it disappears. Usually only spins right before the view appears on the screen.

Ideas?

EDIT: The problem might have to do with the fact I am using a TabBar... In the simulator the ActivityIndicator will spin on Screen/Tab 1 while Screen/Tab 2 is loading. On the phone, I only see the ActivityIndicator for a split second after Screen 2 finally appears.

-(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
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别忘他 2024-09-04 10:43:25

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

[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;

You turn on the spinner here…

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

But immediately you turn it off…

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

Of course it won't show. I'm surprised it shows in the simulator.

The -doneSpinning method should be called after -getDataFromServer is done, or just do

UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
[self getDataFromServer]; // assumes it is blocking.
app.networkActivityIndicatorVisible = NO;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文