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.

Answers


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


Need Your Help

How can 32-bit application find the location of 64-bit Program Files directory on Windows Vista 64-bit?

32bit-64bit vista64

I'm struggling with a problem of how to determine the location of the 64-bit Program Files directory on 64-bit Windows Vista from a 32-bit application.

Entity Framework many-to-many relationship values not saved in database

vb.net asp.net-mvc-4 entity-framework-5

I've set up a many-to-many relationship using Code First and the Entity Framework 5. The join table has been created but the field data does not save to the database.