gpt4 book ai didi

iphone - 进度条不显示 iphone 中的逐步进度

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:39 24 4
gpt4 key购买 nike

大家好,我在我的应用程序中使用进度条来指示 xml 解析的状态。但它没有显示逐步更新,而是在整个 xml 解析结束后加载进度条,直到那个时候卡住了,没有显示任何进展。如何解决这个问题。谁能帮帮我。我使用下面的代码

IBOutlet UIProgressView * threadProgressView;

threadProgressView.progress = 0.0;
[self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];

- (void)makeMyProgressBarMoving
{
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + ((float)1/(float)10);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
else{
/* something else */
}
}

最佳答案

  1. 每 1/10 秒在主线程上创建一个计时器。让它达到你的“makeMyProgressBarMoving”功能。

    myTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:YES];

然后将您的函数编辑为如下所示:

- (void)makeMyProgressBarMoving {

float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + ((float)1/(float)10);
return;
}

//if you got here that means the progress view is greater than 1 so now you can kill your timer that you had running every 1/10th of a second.

[myTimer invalidate];

}

关于iphone - 进度条不显示 iphone 中的逐步进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7578732/

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