Stop and Reset NSTimer

前端 未结 2 1388
小蘑菇
小蘑菇 2021-01-19 07:53

I have a simple timer using that is activated with a button is pushed. It runs from 60 to 0 no problem but what I want is to stop and reset the timer on push button. I have

2条回答
  •  渐次进展
    2021-01-19 08:47

    You need to set the seconds down to 0, otherwise the you always invalidate your timer, but never start it again:

    - (IBAction)timerStart:(id)sender {
        if(!secondCounter == 0) {
            [countdownTimer invalidate];
            secondCounter = 0;
        }
        else {
            [self setTimer];
        }
    }
    

提交回复
热议问题