Reputation: 7444
Currently I am creating a NSTimer that calls my method every one second.
I do this like so:
[NSTimer scheduledTimerWithInterval:1 target:self selector:@selector(clocktick) userInfo:nil repeats:YES];
How can I stop this from calling clocktick
?
I have tried assigning it like so: NSTimer *myTimer = [NSTimer ...
and then using myTimer = nil;
but that did nothing.
Upvotes: 0
Views: 292
Reputation: 8163
You have to hold a reference to it, and then send the invalidate
message to it:
[myTimer invalidate];
I hope it helps!
Upvotes: 3
Reputation: 28688
You need [myTimer invalidate]
that will kill the timer for you.
Upvotes: 4
Reputation: 26
Have you tried using 'invalidate' ([timerInstance invalidate]; for example)?
Or is the problem that you don't have a reference to the timer instance anymore?
Upvotes: 1