Question

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
}
Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top