问题描述
- 不清楚倒计时器的问题
-
需要做一个倒计时器,使用NSTimeInterval。但是标签不更新啊。- (IBAction)startTimer:(id)sender{ timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES]; } - (void)timerAction:(NSTimer *)t { if(testTask.timeInterval == 0){ if (self.timer){ [self timerExpired]; [self.timer invalidate]; self.timer = nil; } else { testTask.timeInterval--; } } NSUInteger seconds = (NSUInteger)round(testTask.timeInterval); NSString *string = [NSString stringWithFormat:@"%02u:%02u:%02u", seconds / 3600, (seconds / 60) % 60, seconds % 60]; timerLabel.text = string; }
解决方案
逻辑错误吧
if(testTask.timeInterval != 0)
时间: 2025-01-21 06:51:31