【问题标题】:UIActivityIndicatorView not spinning till I go back to Parent UITableViewUIActivityIndi​​catorView 在我回到父 UITableView 之前不会旋转
【发布时间】:2010-03-06 18:10:38
【问题描述】:

我有一个使用 UITableViews 并从服务器获取数据的应用程序。我试图在父 UITableView 上放置一个 UIActivityIndi​​catorView,因此它在加载子 UITableView 时旋转。我通过 Interface Builder 等将 UIActivityIndi​​catorView 全部连接起来。

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

所以,当我将 Child UITableView 推到屏幕上时,UIActivityIndi​​catorView(微调器)就在 Parent UITableView 上。如果我转到子 UITableView 然后快速返回父视图,我可以在旋转的动作中捕捉到 UIActivitIndicatorView。 NSLogs 显示在正确的时间 - 当我第一次点击父 UITableView 中的单元格时,“Spin The Spinner”出现在日志中。 9 秒后,我在日志中“完成旋转”,但除非我及时弹回父 UITableView,否则微调器永远不会旋转。

为什么这不能正常工作的想法?

【问题讨论】:

    标签: iphone uitableview spinner uiactivityindicatorview


    【解决方案1】:

    也许 sleepForTimeInterval 阻塞了动画。

    尝试删除 sleepForTimeInterval 并将 performSelectorOnMainThread 替换为对 performSelector:withObject:afterDelay: 的调用。

    【讨论】:

    • 那行得通。谢谢,我怀疑我很快就会发现。我最终取出了 sleepForTimeInterval 并设置了 waitUntilDone:NO,这达到了相同/想要的效果。
    【解决方案2】:

    让用户界面在线程外显示它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多