Note that there are some explanatory texts on larger screens.

plurals
  1. POReinitialize a view controller - iPhone
    text
    copied!<p>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. </p> <p>Here is the code block I am using to load and remove views:</p> <pre><code>-(void)loadStartViewController { [currentView.view removeFromSuperview]; StartViewController *startViewController = [[StartViewController alloc] initWithNibName:@"StartView" bundle:nil]; [window addSubview:startViewController.view]; currentView = startViewController; </code></pre> <p>}</p> <p>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.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload