对于如何在迭代循环的同时更新UIProgressbar的进度,我找不到明确的答案,例如:
for (int i=0;i<items.count;i++) {
Object *new = [Object new];
new.xxx = @"";
new...
...
float progress = (i+1) / (float)items.count;
progressBar.progress = progress;
}
[self save];如何更新独立线程上的UI?
发布于 2014-07-11 20:29:52
在后台线程上运行循环,并更新主线程上的进度条:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
for (int i=0;i<items.count;i++) {
Object *new = [Object new];
new.xxx = @"";
new...
...
float progress = (i+1) / (float)items.count;
dispatch_async(dispatch_get_main_queue(), ^{
progressBar.progress = progress;
});
}
[self save];
});https://stackoverflow.com/questions/24701643
复制相似问题