B1GR0BB1E
B1GR0BB1E

Reputation: 85

Validate a NSTimer that was invalidated

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?

Upvotes: 8

Views: 3403

Answers (2)

rebello95
rebello95

Reputation: 8576

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];

Upvotes: 5

Hyperbole
Hyperbole

Reputation: 3947

Unfortunately, no.

From the docs:

Once invalidated, timer objects cannot be reused.

Just make a new one.

Upvotes: 10

Related Questions