I create a quiz game. Here is a part of my code:
- (void) viewDidLoad
{
logos = [[NSMutableArray alloc] init];
[logos addObject:@"adidas"];
[logos addObject:@"nike"];
[logos addObject:@"puma"];
[self showLogo];
}
int currentQuestionIndex;
- (void) showLogo
{
currentQuestionIndex++;
NSString *question = [logos objectAtIndex:currentQuestionIndex];
[_questionImage setImage:[UIImage imageNamed:question]];
...
}
If user will choose the right answer, "showLogo" will be called again to go to next question. So, Level is completed.
Everything works great.
Please help me to save the information/levels. IF level is completed, when user Launch game he have to start with saved level.
This is what I tried already:
- (void) checkAnswer
{
///... if user answered right
[[NSUserDefaults standardUserDefaults] setInteger:currentQuestionIndex forKey:@"currentLevel"];
[self showLogo];
/// so, I tried to save "currentQuestionIndex" forKey currentLevel, and call "showLogo"
}
and here is modified "showLogo"
- (void) showLogo
{
int savedLevel = [[NSUserDefaults standardUserDefaults] integerForKey:@"currentLevel"];
currentQuestionIndex = savedLevel+1 ;
NSString *question = [logos objectAtIndex:currentQuestionIndex];
[_questionImage setImage:[UIImage imageNamed:question]];
...
}
but doesn't work.. using this method, I tried to save score, and it works also..
Help please. Thanks