I have a multi view application with individual UIViewControllers and xibs. I have one view that is the game view and every time I call it I want it to re-initialize, by that I mean restart at it's initial condition and not in the state I last left it in.
Here is the code block I am using to load and remove views:
-(void)loadStartViewController {
[currentView.view removeFromSuperview];
StartViewController *startViewController = [[StartViewController alloc] initWithNibName:@"StartView" bundle:nil];
[window addSubview:startViewController.view];
currentView = startViewController;
}
I should be more clear here. I have a UIViewController and a xib that make up the view while the game is being played. They call a method in a UIView to programatically draw the view. I leave the UIViewController when the game ends and I go to a score screen. I want to have the user restart and go back into the game, IE load the UIViewController with the above code but start with a new game, all settings are in the method called. I could just set a variable and pass it between UIViewControllers but I though there might be a command that would allow me to reset the game UIViewController so it does not remember anything about the state at the end of the last game.
To make it work I wrote a method to reset all the variables in the UIView that draws the game screen and call that method from the UIViewController in the viewDidLoad section.