0

我有数学函数(大约 O^(10^7)),在搜索结果时我必须显示进度。所以我有进度条。问题是,如何更新进度条?我试图这样做:

self.progressBar.progress = 0.0;
self->progress = 0.0;
for (1..10^7) {
    ...
    if (self.progressBar.progress < self.progress + 0.01) {
        [self updateProgress];
    }
}
[self updateProgress];
4

2 回答 2

2

在单独的线程中运行该操作。这是必须的。

你能把操作分成几个步骤吗?你知道步数吗?然后在每一步之后将进度条更新为stepIndex/numSteps百分比。

If you can't divide the operation into steps but you know how long the operation will take, you can update the bar to timeSinceStart/expectedTime percents. Use a NSTimer for the periodic updates.

If you can't do that, use only a UIActivityIndicator, that is, a component that shows the application is doing something but showing no indication how long the operation can take.

于 2013-03-29T22:12:53.177 回答
1

有时你必须这样做:

CFRunLoopRunInMode (CFRunLoopCopyCurrentMode(CFRunLoopGetCurrent()), 0, FALSE);

让 UI 更新进度条。

另外..您有动画:是的,并且并非在所有版本的iOS中都可用。

您可能需要在 updateProgress 方法中考虑:

if ([activityProgressView respondsToSelector:@selector(setProgress:animated:)]) {
    [activityProgressView setProgress:0.5 animated:YES];
}
else {
    [activityProgressView setProgress:0.5];
}
CFRunLoopRunInMode (CFRunLoopCopyCurrentMode(CFRunLoopGetCurrent()), 0, FALSE);
于 2013-03-29T22:06:16.297 回答