gpt4 book ai didi

ios - 进度 View 循环

转载 作者:行者123 更新时间:2023-11-29 11:55:15 29 4
gpt4 key购买 nike

我希望这个进度 View 在完成后基本上“重置”。

尝试将计数重置为 0,它确实重置了,但是对于每次重置,计时器只会变得越来越快。

.h

@property (nonatomic, strong) NSTimer *myTimer;
@property (weak, nonatomic) IBOutlet UILabel *progressLabel;

.m

- (void)updateUI:(NSTimer *)timer
{
static int count = 0; count++;

if (count <=100)
{
self.progressView.progress = (float)count/100.0f;
}
else
{
self.myTimer = nil;
[self.myTimer invalidate];
// shoot method for next question
count = 0;

self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];

self.progressView.center = self.view.center;
[self.view addSubview:self.progressView];

self.myTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(updateUI:) userInfo:nil repeats:true];
}
}

最佳答案

在将计时器设置为nil 之前,您需要先使其无效。截至目前,您对 invalidate 的调用是空操作。这意味着您会不断添加越来越多的事件计时器。

关于ios - 进度 View 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39378394/

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