I'm running into a strange problem in my app. I'm using an NSTimer as a countdown timer before beginning a new 'round'. The idea is that the timer starts with an initial value and then decrements each time the timer fires. This then shows up on an alert view I have showing. All of the logic for this works and is in place.
The problem is that my timer isn't firing!
You'll have to forgive my pseudocode, but I think it will make more sense than my present code.
In my view controller
Code:
-(void)loadingFinished
{
show an alert view with %d seconds remaining, where %d is gotten from a property of the timerManager class
//Start the countdown
tell the timerManager to start the countdown timer
}
Other code including notification selectors for notifications sent by the timerManager class
and in my timerManager class
Code:
-(void)startCountdownTimer
{
create a scheduled timer calling a selector within this class
}
..Selector called by the timer which dispatches a notification
The thing is, I've stuck NSLog statements into the selector in timerManager, and the selector is never called. The timer exists and is valid and everything, but it never fires (not even with an unrecognized selector)
I've tried removing the alertView to see if that's causing the problem (modal blocking or something), but no luck there either. Same problem.
In the view controller. alertView is a UIAlertView that is created to display loading information. Getting rid of this view has no effect on the behavior of the timer.
It isn't and I really have it in there for correctness, but changing that (and the corrisponding selector signature) has had no effect.
Like I said... I can't imagine the run loop is blocking or anything since the alert view has no effect. Manually creating a timer and adding it to the run loop ends up with the same results too.
I tried calling a timer from within the view controller to see if any timer is firing. No luck there either. This exists whether the UIAlertView is there or not
Has anyone else had this issue/has any idea what is going on?
Edit: UPDATE: The issue appears to be associated with a separate thread I'm calling in another class, as commenting out the actual 'loading' process fixes this. I guess I'll just have to keep digging :P
Edit: SOLVED: Turns out that by sending a notification from the branched thread, the timer was called on the branched thread, and when that thread terminated, the timer didn't exist. Whoopsies :P
Using a 'performSelectorOnMainThread:' call fixed it.
Edit: SOLVED: Turns out that by sending a notification from the branched thread, the timer was called on the branched thread, and when that thread terminated, the timer didn't exist. Whoopsies :P
Using a 'performSelectorOnMainThread:' call fixed it.
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.
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.