gpt4 book ai didi

ios - UIProgressView 未按预期更新

转载 作者:行者123 更新时间:2023-11-29 04:09:43 26 4
gpt4 key购买 nike

遵循 this question 中概述的答案,我设法让 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

这表明即使文件已经收到的值没有增加,进度仍在增加,我不明白为什么。

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

最佳答案

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

添加

因此,请详细了解如何调用此函数,这将解决问题

关于ios - UIProgressView 未按预期更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14609798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com