简体   繁体   中英

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.

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:

try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM