按照这个问题中概述的答案,我设法让 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
这表明即使文件已经收到的值不是并且我不明白为什么,进度也在增加。
我有一种感觉,我错过了一些明显的东西,但如果有人能指出我做错了什么,我会很感激?谢谢。