Question

I am trying to make a game where you can start from the beginning, "Level 1", and continue to play or start from where you last left off, ex. "Level 8". I want to be able to use one button, "Continue Current Game", on the opening viewcontroller to start where you last left off. I have a separate button to start over. I plan on using an NSInteger to keep track of the levels by adding 1 to it after every level is complete. So I guess the ultimate question is, how do I program the "Continue Current Game" button to go straight to the correct viewcontroller, ex. "Level 8", using the NSInteger or a simpler method? Thanks.

By the way I'm using xcode 5 and a single view template.

Was it helpful?

Solution

use this when you go to the desired level

//level you game
int lvlGame = 0;
//name you UIViewController by level
NSString * nameVC = [[NSString alloc] initWithFormat:@"gameLvl%i",lvlGame];

if use XIB

UIViewController * viewController = [[UIViewController alloc] initWithNibName:nameVC bundle:nil];

if use Storyboard

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController * viewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:nameVC];

and finally

[self.navigationController pushViewController:viewController animated:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top