for循环内更新UIProgressView
我已经搜索过这个问题,唯一的提示是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试设置进度值
try this to set the progress value