8

How can I recall or reestablish a timer that was previously invalidated?

I am trying to allow the user to revalidate/restart a timer when they click a button. Is this possible?

Eugene
  • 9,242
  • 2
  • 30
  • 29
B1GR0BB1E
  • 85
  • 1
  • 5

2 Answers2

10

Unfortunately, no.

From the docs:

Once invalidated, timer objects cannot be reused.

Just make a new one.

Hyperbole
  • 3,917
  • 4
  • 35
  • 54
5

When you invalidate a timer, set it to nil. Then you'll be able to point it to a new NSTimer object.

Example:

//When you're done using your timer
[timer invalidate];
timer = nil;

//When you want to use it again
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tick) userInfo:nil repeats:TRUE];
rebello95
  • 8,486
  • 5
  • 44
  • 65
  • Setting a variable to `nil` then assigning a new pointer to it is not the same is reinitializing the previous object. – Hyperbole Aug 08 '14 at 19:46