Ios UIProgressView未按预期更新

Ios UIProgressView未按预期更新,ios,xcode,uiprogressview,uiprogressbar,Ios,Xcode,Uiprogressview,Uiprogressbar,按照中概述的答案,我设法使UIProgressView正常工作,但它似乎在应该更新之前完成了更新(即栏“填满”) 我尝试添加一些日志语句以查看发生了什么: float actual = [_progressBar progress]; if (actual < 1) { _progressBar.progress = actual + ((float)numberOfFIlesAlreadyDownloaded/(float)numberOfFilesToBeDownloaded

按照中概述的答案,我设法使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];
}
这表明即使已经收到的文件的值不是,进度也在增加,我不明白为什么


我有一种感觉,我错过了一些显而易见的事情,但如果有人能指出我做错了什么,我会很感激的?谢谢。

假设50%的文件已下载,则进度将为0.5。接下来,如果下载延迟,它会根据
\u progressBar.progress=actual+((float)numberoffilesalreadydownload/(float)numberoffilestobedownload)进行添加

因此,请继续讨论如何调用此函数,这将解决问题

 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