In need of help with Timers

I am working on an app that displays a timer countdown, the time will vary based on settings but it will start at say 30 seconds and count down to 0 as soon it hits 0 it will change to another value like 45 and count down from there. Is there a way to put the values in an array and load each one after the other has finished or can multiple timers be put into a for loop and fired that way. I have tried the for loop but it immidiately fires all of them and just adds all the counts together. I would really prefer the option to fill an array with values and go that route but I can't find anything online in regards to what I am trying to accomplish.

Replies

Generally I find multiple timers a difficult thing to program. I prefer a single timing loop to continually check what is going on, using the actual real time from an NSDate, and recording events as they would occur in real time (e.g. 30 seconds from now). This also has the advantage that you can shut off the app and then turn it back on again and all your times remain 'correct'.

Could I see an example of this?

-(void)startClock{//call this method to start/restart the time
    adjustedStartTime=[[NSDate date] timeIntervalSinceReferenceDate];
    [self displayTime];
}
-(void)displayTime{
    int theTime=[[NSDate date] timeIntervalSinceReferenceDate]-adjustedStartTime;
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(displayTime) object:nil];
    [self performSelector:@selector(displayTime) withObject:nil afterDelay:1.0f];
}
-(void)dealloc{ // careful not to call method after dealloc
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(displayTime) object:nil];
}