Search code examples
iosobjective-cnstimer

How to release NSTimer? or stop timer. Xcode 5


After the end of our game the NSTimer does not stop.

-(void)StartGame{
Countdown = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(TimeDecrease) userInfo:nil repeats:YES];
}

-(void)TimeDecrease{
    StartTime = StartTime - 1;
    Timer.text = [NSString stringWithFormat:@"%d",StartTime];
    if(StartTime == 0){
        [self EndGame];
    }
}

We tried [Countdown release] and disabled ARC but it throws an error. We are trying to accomplish a timer that resets to 15 at the beginning of every new game.


Solution

  • Try:

    [Countdown invalidate];
    Countdown = nil;