0

按照这个问题中概述的答案我设法让 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

这表明即使文件已经收到的值不是并且我不明白为什么,进度也在增加。

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

4

1 回答 1

1

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

所以仔细看看你是如何调用这个函数的,这将解决问题

于 2013-01-30T17:22:09.773 回答