使用简单的操作,设置计时器
- (IBAction)timerStart:(id)sender {
if(!secondCounter == 0){
[countdownTimer invalidate];
}
else {
[self setTimer];
}
}
计时器的代码
- (void)timerRun {
secondCounter = secondCounter - 1;
int minutes = secondCounter;
NSString *timerOutput = [NSString stringWithFormat:@"%d", minutes ];
countDownLabel.text = timerOutput;
if(secondCounter == 0){
[countdownTimer invalidate];
countdownTimer = nil;
}
}
- (void)setTimer {
secondCounter = 60;
countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];
}