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 に答える