开发者

UIActivityIndicatorView not spinning till I go back to Parent UITableView

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 NS开发者_Go百科Logs 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?


Perhaps the sleepForTimeInterval is blocking the animation.

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


let the ui display it outside thread:

[NSObject dispatchUI:^{
     [spinner startAnimating];
}];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜