Use scheduledTimerWithTimeInterval instead. The one you used will only fire when added to a run loop.
Quote:
Originally Posted by jazztpt
Hi, I think I'm having the same problem and I was hoping you could provide a little code or advice. I have tried this to make sure it's on the main thread, but neither of my NSLogs are happening, so it should already be on the main thread and the timer is never being fired.
Code:
-(void)viewWillAppear:(BOOL)animated {
...other code...
_countdown = 15;
if ([NSThread currentThread] != [NSThread mainThread]) {
NSLog(@"not the main thread");
[self performSelectorOnMainThread:@selector(createTimer) withObject:nil waitUntilDone:YES];
} else {
[self createTimer];
}
}
-(void) createTimer {
_countdownTimer = [[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats:YES] retain];
}
-(void)updateCountdown {
NSLog(@"yo");
if (_countdown > 0) {
_countdown--;
} else {
[_countdownTimer invalidate];
[_countdownTimer release];
_countdownTimer = nil;
...do other stuff...
}
}
Any thoughts on why this timer is not firing?
|