UIActivityIndi​​catorView 不旋转,直到我返回到父 UITableView

发布于 2024-08-24 06:55:41 字数 1504 浏览 6 评论 0原文

我有一个使用 UITableViews 并从服务器获取数据的应用程序。我试图将 UIActivityIndi​​catorView 放在父 UITableView 上,以便在加载子 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];                   
}

因此,当我将子 UITableView 推到屏幕上时,UIActivityIndi​​catorView (旋转器)就位于父 UITableView 上。如果我转到子 UITableView,然后快速返回到父视图,我可以捕获正在旋转的 UIActivitIndicatorView。 NSLogs 在正确的时间显示 - 当我第一次点击父 UITableView 中的单元格时,“旋转微调器”出现在日志中。 9 秒后,我在日志中“完成旋转”,但旋转器永远不会旋转,除非我及时弹回父 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 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?

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

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

发布评论

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

评论(2

又怨 2024-08-31 06:55:41

也许 sleepForTimeInterval 正在阻止动画。

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

Perhaps the sleepForTimeInterval is blocking the animation.

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

﹂绝世的画 2024-08-31 06:55:41

让 ui 在线程外显示它:

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

let the ui display it outside thread:

[NSObject dispatchUI:^{
     [spinner startAnimating];
}];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文