【发布时间】:2015-05-01 22:52:14
【问题描述】:
我想倒计时 23 小时。我的代码可以完美地倒计时,但是当我退出应用程序或切换到应用程序中的另一个视图控制器/页面时它不起作用
即使应用程序已关闭并使用 NSUserDefaults 切换到另一个视图控制器,我也希望它运行
请帮忙,如果需要,我可以提供更多代码
-(void) timerRun {
secondCount = secondCount - 1;
int hours = (secondCount/ 3600) % 24;
int minuts = (secondCount / 60) % 60;
int seconds = secondCount % 60;
NSString *timerOutput = [NSString stringWithFormat:@"%2d:%.2d:%2d", hours, minuts, seconds];
countdownLabel.text = timerOutput;
if (secondCount == 0) {
[countdownTimer invalidate];
countdownTimer = nil;
}
}
-(void) setTimer {
secondCount = 82800;
countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];
}
- (IBAction)start:(id)sender {
[self setTimer];
}
【问题讨论】:
标签: objective-c nstimer countdown countdowntimer