Reputation: 77
I have looked around on google and stack exchange but i couldn't find the correct information I was looking for.
I am creating a game. Rather than having an 'About' or 'instructions' page that the user needs to go to, to find out how to play, I would like the instructions to come up as a view controller where the user can read the instructions and continue to play from there. THOUGH I want this to only happen once! So the 2nd time the user goes to play the game it goes straight to the game play.
Does anyone know how this would be done?
Thanks in advance, Matt
Upvotes: 0
Views: 97
Reputation: 3393
use NSUserDefaults, like
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if ([identifier isEqualToString:@"yourSegueName"])
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if([defaults objectForKey:@"IS_FirstTime"]!=nil)
{
//user came for first time show help screen
[defaults setObject:@"IT'sNotFirstTime" forKey:@"IS_FirstTime"];
[defaults synchronize];
return(true);
}
else
{
//don't show help screen
return(fale);
}
}
else
{
return(true);
}
}
Upvotes: 1
Reputation: 1547
In your main view controller decide whether you push the instructions view controller or not based on a value that you save in user defaults:
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showInstructions"]
In viewDidLoad
, for example:
if([[NSUserDefaults standardUserDefaults] boolForKey:@"showInstructions"]) {
[self performSegueWithIdentifier:@"instructionsSegue"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"showInstructions"];
}
Upvotes: 1