我正在使用NSTimer
,
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES];
然后是我的60秒倒数计时器程序
-(void) updateCountdown {
int hours, minutes, seconds;
secondsLeft++;
hours = secondsLeft / 3600;
minutes = (secondsLeft % 3600) / 60;
seconds = (secondsLeft %3600) % 60;
time.text = [NSString stringWithFormat:@"%02d", seconds];
}
我的问题是在60秒后解雇我的倒计时控制器页面..任何人都可以帮助我
答案 0 :(得分:7)
如果repeats: YES];
检查seconds
达到或大于60
,请使计时器无效并解除您的VC
if (seconds >60)
{
[timer invalidate];
[self dismissViewControllerAnimated:YES completion:nil];
}
其他使用repeats: NO];
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: NO];
并调用函数
-(void) updateCountdown {
[timer invalidate];
[self dismissViewControllerAnimated:YES completion:nil];
}
答案 1 :(得分:2)
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown:) userInfo:nil repeats: NO]; // set No
-(void) updateCountdown:(NSTimer *)timer
{
[timer invalidate];
// dismiss your controller
}