简体   繁体   中英

UIProgressView not updating as expected

Following the answer outlined in this question , I managed to get a UIProgressView sort-of working but it seems to finish updating (ie the bar "fills up") before it should.

I tried adding some log statements to see what was going on:

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];
}

This outputs:

 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

This suggests that the progress is being incremented even when the files already received value is not and I don't understand why.

I've a feeling I've missed something obvious but would appreciate it if anyone can point out what I'm doing wrong? Thanks.

suppose the 50% of files are downloaded so progress will be 0.5. Next if there is a delay in download still it adds according to _progressBar.progress = actual + ((float)numberOfFIlesAlreadyDownloaded/(float)numberOfFilesToBeDownloaded);

So go through on how are you calling this function and this will solve the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM