I am using static int variables but having some problem. Problem is that its not getting reset.
If I leave this page and come again then I found previous values while I have reset it.
Please give me solution.
here is my code
- (void)updateQuestion:(NSTimer *)theTimer {
static int questionCounter = 1;
questionCounter += 1;
count=(questionCounter%QUESTION_TIME_LIMIT);
tfLeftTime.text=[NSString stringWithFormat:@"%d",QUESTION_TIME_LIMIT];
tmLeftTime=[[NSTimer alloc] init];
tmLeftTime=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateLeftTime:) userInfo:nil repeats:YES];
[self playMusic];
if (questionCounter>QUESTION_PER_LEVEL) {
if ([tmQuestion isValid]) {
[tmQuestion invalidate];
questionCounter=1;
count=1;
tmQuestion=nil;
[self showAdvertisement];
}
}
}
Thank & Regards
Shivam
You can also use a instance variable to have the effect you want.
The counter will remain as long as the object lives, and is destroyed when you no longer need it.