Does any one want to teach me how to using loop process using NSTimer
? I have 2 process timer to do, timer1 and timer2 repeated to n loop (timer1 -> timer2 -> timer1 -> timer2 and so on until n loop) that are triggered by a button. I am new to xcode. please teach me. both timer has input by user. please give me example if possible.
My code should be like this. Corret me if i'm wrong
- (void) timer2Elapsed:(NSTimer *) timer;
{
...
displayCountDown.text = [NSString stringWithFormat:@"%d : %d : %d", hour , minute, second];
}
- (void)timer1Elapsed: (NSTimer *) timer;
{
...
displayCountDown.text = [NSString stringWithFormat:@"%d : %d : %d", hour , minute, second];
}
My button who trigger the countdown:
- (IBAction)startBtn:(id)sender {
endSetTime = [NSDate timeIntervalSinceReferenceDate] + totalSecondTime;
endSetRest = [NSDate timeIntervalSinceReferenceDate] + totalSecondRest;
countdownTimer = [NSTimer scheduledTimerWithTimeInterval: 0.99 target: self selector: @selector(timer1Elapsed:) userInfo: nil repeats: YES];
}
someone here told me to using this code but i don't know what should i write inside and where to put it in? He said for looping? I don't know? And how to connect that code inside my button?
+ (void) startTimer:(id)timer
{
static int numberOfTimes = 0;
if(numberOfTimes >= 5)
{
numberOfTimes = 0;
return;
}
numberOfTimes ++;
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timer1Elapsed:) userInfo:nil repeats:NO];
}