i am working in iPhone application, Using NSTimer to create time count to set in the screen like initially 100 then elapsed like 99,98,97 etc… if i have completed the game with available elapsed time, then i showed AlertView like successfully finished, the user press ok button navigate to previous screen, then again go to game screen, at the time ellapsed time start with previous elapsed time like 66,65,64 etc… i want, when the user go to game screen again the time count start with 100, how to fix this issue?, please help me
Thanks in Advance
I tried this:
- (void)viewDidLoad
{
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(elapsedTime) userInfo:nil repeats:YES];
}
-(void)elapsedTime
{
static int i = 100;
NSLog(@"i:%d",i);
lbl.text = [NSString stringWithFormat:@"%d",i];
i--;
if(i<0)
{
[timer invalidate];
timer = nil;
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[timer invalidate];
timer = nil;
[self.navigationController popViewControllerAnimated:YES];
}
Define int i as class variable in .h file