views:

396

answers:

1

I have an App using UITableViews and fetching data from a server. I am attempting to put a UIActivityIndicatorView on the Parent UITableView, so it spins while the Child UITableView is loading. I have the UIActivityIndicatorView all hookedup through Interface Builder, etc.

-(void)spinTheSpinner {
    NSLog(@"Spin The Spinner");
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [spinner startAnimating];
    [NSThread sleepForTimeInterval:9];
    [self performSelectorOnMainThread:@selector(doneSpinning) withObject:nil waitUntilDone:NO];
    [pool release]; 
}

-(void)doneSpinning {
    NSLog(@"done spinning");
    [spinner stopAnimating];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [NSThread detachNewThreadSelector:@selector(spinTheSpinner) toTarget:self withObject:nil];

    NSMutableString *tempText = [[NSMutableString alloc] initWithString:[categoryNumber objectAtIndex:indexPath.row]];
    Threads *viewController = [[Threads alloc] initWithNibName:@"newTable" bundle:nil tagval:tempText SessionID:PHPSESSID];
    [self.navigationController pushViewController:viewController animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    [viewController release];                   
}

So, when I push the Child UITableView onto the screen, the UIActivityIndicatorView (spinner) just sits there on the Parent UITableView. If I go to the Child UITableView and then quickly go back to the Parent View, I can catch the UIActivitIndicatorView in the act of spinning. The NSLogs are showing at the correct times - when I first tap the cell in the Parent UITableView, the "Spin The Spinner" appears in the Log. 9 seconds later, I get "done spinning" in the Log, but the spinner never spins unless I pop back to the Parent UITableView in time.

Ideas of why this is not working properly?

+1  A: 

Perhaps the sleepForTimeInterval is blocking the animation.

Try removing the sleepForTimeInterval and replace performSelectorOnMainThread with a call to performSelector:withObject:afterDelay:.

DyingCactus
That worked. Thank you, doubt I would have found that anytime soon. I ended up taking out the sleepForTimeInterval and setting waitUntilDone:NO, and that achieved the same / desired effect.
Chris