for循环内更新UIProgressView

发布于 2024-11-09 14:26:21 字数 840 浏览 5 评论 0原文

我已经搜索过这个问题,唯一的提示是performSelectorOnMainThread 解决方案。我这样做了,但在 for 循环运行时视图没有更新。循环结束后,进度值会正确显示 - 但这不是“进度”视图的重点 =)

for 循环位于控制器内。我调用一个方法来设置进度值:

CGFloat pr = 0.5; // this value is calculated
[self performSelectorOnMainThread:@selector(loadingProgress:) withObject:[NSNumber numberWithFloat:pr] waitUntilDone:NO];

这是加载进度方法

-(void)loadingProgress:(NSNumber *)nProgress{
    NSLog(@"Set Progress to: %@", nProgress);
    [[self progress] setProgress:[nProgress floatValue]];
}

我还尝试通过在方法顶部使用此方法将带有 for 循环的方法放入后台线程:

    if([NSThread isMainThread]) {
        [self performSelectorInBackground:@selector(importData) withObject:nil];
        return;
    }
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  

也许有人可以帮助我解决这个问题。

I've already searched for the problem, and the only hint was the performSelectorOnMainThread solution. I did that, but the view is not updating while the for loop is running. After the loop the progress value is displayed correctly – but that's not the point of an "Progress" View =)

The for loop is within a controller. I call a method to set the progress value:

CGFloat pr = 0.5; // this value is calculated
[self performSelectorOnMainThread:@selector(loadingProgress:) withObject:[NSNumber numberWithFloat:pr] waitUntilDone:NO];

And this is the loading progress method

-(void)loadingProgress:(NSNumber *)nProgress{
    NSLog(@"Set Progress to: %@", nProgress);
    [[self progress] setProgress:[nProgress floatValue]];
}

I also tried to put the method with the for loop into a background thread by using this at the top of the method:

    if([NSThread isMainThread]) {
        [self performSelectorInBackground:@selector(importData) withObject:nil];
        return;
    }
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  

Maybe somebody can help me with this.

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

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

发布评论

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

评论(1

且行且努力 2024-11-16 14:26:21
 CGFloat pr = 0.5; // this value is calculated
[self performSelectorInBackground:@selector(loadingProgress:) withObject:[NSNumber numberWithFloat:pr]];

尝试设置进度值

 CGFloat pr = 0.5; // this value is calculated
[self performSelectorInBackground:@selector(loadingProgress:) withObject:[NSNumber numberWithFloat:pr]];

try this to set the progress value

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