S.J
S.J

Reputation: 3071

How to detect NSTimer selector called or not

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self.theTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(timerFire:) userInfo:nil repeats:NO];

//if(timerFire not called) {other code}
    }

How can I detect if timerFire: not called. If timerFire: is not called then I want to perform some other activity.

Upvotes: 0

Views: 117

Answers (2)

Dheeraj Singh
Dheeraj Singh

Reputation: 5183

try this

if ([self respondsToSelector:@selector(timerFire:)])
{
// Your Code
}
else
{
}

Upvotes: 0

nburk
nburk

Reputation: 22731

It's not quite clear what you're asking here.

In any normal situation the timer is going to fire and thus timerFire: will be called.

This will not happen if:

  1. you did not actually implement timerFire: in the class which you set as a target (so, in this case it's self). you can check this with respondsToSelector:?

  2. the timer is invalidated before the interval of 0.2 sec is over, in that case you can use a global variable in your class (something like BOOL timerDidFire) and set it to YES in timerFire:

Upvotes: 1

Related Questions