Why does my NSTimer selector never fire? Is it because it's in GLKitViewController instead of UIViewController?
At a certain state in the program, I call a method with this as the body:
self.timeStartedDisplayingTime = [NSDate date]; self.stopButton.enabled = YES; [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateElapsedTime:) userInfo:nil repeats:YES];
I've verified that this method is indeed called.
However, the corresponding selector's body:
NSTimeInterval elapsedTimeDisplayingECG = [self.timeStartedDisplayingECG timeIntervalSinceDate:[NSDate date]]; self.elapsedTimeValueLabel.text = [NSString stringWithFormat:@"%f", elapsedTimeDisplayingECG];
Is never called. I've put a breakpoint on it and it's never reached. Why is this exactly? It's in a GLKitViewController instead if that's relevant.
Your timer gets thrown away right after creating it. You need to retain is somewhere.
Define a property
@property (strong) NSTimer *myTimer;
and assign your timer to this:
self.myTimer = [NSTimer scheduledTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateElapsedTime:) userInfo:nil repeats:YES];