Pangolin
Pangolin

Reputation: 7444

How can I stop my NSTimer thread from further executing the selector

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

Answers (3)

Fran Sevillano
Fran Sevillano

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

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

You need [myTimer invalidate] that will kill the timer for you.

Upvotes: 4

blueyond
blueyond

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

Related Questions