1
如何编写代码如果timer1Elapsed完成倒数计时器然后转到下一个timer2Elapsed,倒计时后返回timer1Elapsed倒计时等等重复过程5次。似乎(A→B→A→B ... 5次)在条件A和B有固定时间,就说A计1分钟,B计30秒。请帮助,请不要错别字,因为我是初学者。纠正我,如果我的代码是错误的。请慷慨。NSTimer如何解决我的代码
- (void) timer2Elapsed:(id)timer
{
...
if (remainingTime <= 0)
{
[timer invalidate];
[NSTimer scheduledTimerWithTimeInterval:0.99 target:self selector:@selector(timer3Elapsed:) userInfo:nil repeats:YES];
}
myDisplay.text = [NSString stringWithFormat:@"%d : %d : %d", hour , minute, second];
}
- (void) timer1Elapsed:(id)timer
{
...
if (remainingTime <= 0)
{
[timer invalidate];
[NSTimer scheduledTimerWithTimeInterval:0.99 target:self selector:@selector(timer2Elapsed:) userInfo:nil repeats:YES];
}
myDisplay.text = [NSString stringWithFormat:@"%d : %d : %d", hour , minute, second];
}
这是我的按钮
- (IBAction)startBtn:(id)sender {
[NSTimer scheduledTimerWithTimeInterval:0.99 target:self selector:@selector(timer1Elapsed:) userInfo:nil repeats:YES];
}
如何使用它的循环?只是说5次重复? – Piyo
在你的班级中增加一个计数器变量,每增加一个计时器被调用,当它达到5时,不计划一个新的计时器 –
@Piyo检查更新的答案,它显示如何使用static int将其限制为5次 –