hello,
I made an NSTimer to start when a user taps, my problem is that if the user taps again (after the NSTimer started) another timer will be lunched and the time displayed will be moving crazy fast, how to fix that?
Thanks
I made an NSTimer to start when a user taps, my problem is that if the user taps again (after the NSTimer started) another timer will be lunched and the time displayed will be moving crazy fast, how to fix that?
Thanks
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if(timerBOOL==TRUE)
{
[timer invalidate];
timerBOOL = FALSE;
} else {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countUp) userInfo:nil repeats:YES];
timerBOOL = TRUE;
}
}
-(void)countUp {
mainint += 1;
myTextFeild.text = [NSString stringWithFormat:@"%i secs", mainint];
}