UIProgressView未按预期更新

时间:2013-01-30 17:14:01

标签: ios xcode uiprogressview uiprogressbar

按照this question中概述的答案,我设法让UIProgressView 排序正常工作,但似乎在它应该完成之前完成更新(即“填满”栏)。

我尝试添加一些日志语句来查看发生了什么:

float actual = [_progressBar progress];

if (actual < 1) {
    _progressBar.progress = actual + ((float)numberOfFIlesAlreadyDownloaded/(float)numberOfFilesToBeDownloaded);

    NSLog(@"progress = %f", _progressBar.progress);
    NSLog(@"expected = %d", numberOfFilesToBeDownloaded);
    NSLog(@"received = %d", numberOfFIlesAlreadyDownloaded);
    NSLog(@"actual = %f", actual);

    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(animateProgressBar) userInfo:nil repeats:NO];
}

输出:

 progress = 0.114286
 expected = 35
 received = 4
 actual = 0.000000
 progress = 0.285714
 expected = 35
 received = 6
 actual = 0.114286
 progress = 0.571429
 expected = 35
 received = 10
 actual = 0.285714
 progress = 0.857143
 expected = 35
 received = 10
 actual = 0.571429
 progress = 1.000000
 expected = 35
 received = 10
 actual = 0.857143 // this is the last output

这表明即使已经收到的文件没有得到进展也会增加,我不明白为什么。

我有一种感觉,我已经错过了一些明显的东西,但如果有人能指出我做错了什么,我会很感激吗?感谢。

1 个答案:

答案 0 :(得分:1)

假设下载了50%的文件,因此进度为0.5。接下来如果下载有延迟,它仍会根据_progressBar.progress = actual + ((float)numberOfFIlesAlreadyDownloaded/(float)numberOfFilesToBeDownloaded);

添加

请仔细研究如何调用此函数,这将解决问题