ボタンを押すと起動するシンプルなタイマーを使用しています。60 から 0 まで問題なく動作しますが、押しボタンでタイマーを停止してリセットしたいのです。以下のコードを使用してボタンが押されたときに停止することができましたが、何らかの理由でリセットして 60 で停止することができません。これは単純なはずですが、機能していません。助言がありますか?
シンプルなアクションでタイマーをセット
- (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];
}