Hi, my nstimer reset button is not working and when i click on it, it will reset the label to 2:00 but when i press the start button again it will carry on as if the reset button was never pressed.
here is my code:
Code:
- (void)countDownOneSecond
{
seconds--;
int currentTime = [timerLabel.text intValue];
int newTime = currentTime - 1;
int displaySeconds = !(seconds % 60) ? 0 : seconds < 60 ? seconds : seconds - 60;
int displayMinutes = floor(seconds / 60);
NSString *time = [NSString stringWithFormat:@"%d:%@%d",
displayMinutes,
[[NSString stringWithFormat:@"%d", displaySeconds] length] == 1 ? @"0" : @"",
displaySeconds
];
timerLabel.text = time;
if(seconds == 0)
{
[timer invalidate];
}
}
- (void)startOrStopTimer
{
if(timerIsRunning){
[timer invalidate];
[startOrStopButton setTitle:@"Start" forState:UIControlStateNormal];
} else {
timer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDownOneSecond) userInfo:nil repeats:YES] retain];
[startOrStopButton setTitle:@"Stop" forState:UIControlStateNormal];
}
timerIsRunning = !timerIsRunning;
}
- (void)resetTimer
{
[timer invalidate];
[startOrStopButton setTitle:@"Start" forState:UIControlStateNormal];
[timer invalidate];
timerLabel.text = @"2:00";
}