0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Doug Smith
  • 29,668
  • 57
  • 204
  • 388

1 Answers1

-1

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];

343max
  • 400
  • 1
  • 12