I\'m trying to create a countdown timer that takes countdown, an IBOutlet connected to a textfield, from 60 seconds down to 0. I\'m not sure
A. How to limit the repeat
You can add a instance variable int _timerValue to hold the timer value and then do the following. Also note that the NSTimer you are creating is already scheduled on the current run loop.
- (IBAction)startCountdown:(id)sender
{
_timerValue = 60;
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(advanceTimer:) userInfo:nil repeats:NO];
}
- (void)advanceTimer:(NSTimer *)timer
{
--_timerValue;
if(self.timerValue != 0)
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(advanceTimer:) userInfo:nil repeats:NO];
[countdown setIntegerValue:_timerValue];
}