Switching between UIViewContollers

Posts: 1
Joined: 2010.05
Post: #1
I am trying to make a simple card game that loads a menu screen first that gives the user the option to choose "Play Game" or "Settings". I am trying to find that best way to handle transitioning between these three UIViewControllers and a rootViewController. I have set up four UIViewControllers:
1) rootViewController
2) menuViewController
3) playerBoardViewController
4) settingsViewController
Each one has it's own nib where I designed the views and placed the buttons to move to the other views. The rootControllerView uses the mainWindow nib that has nothing on it, later I was planning on adding a splash screen on a timer before it loaded the menuViewController. The issue I have is how to have a button that calls an IBAction method to load the next UIViewController and unload the current one which happens to be the one that the button belongs to.
This has to be a simple problem to fix as just about every game on the appStore works like this. So, how does one go about loading a different UIViewController with it's nib from a button on the current UIViewController and "be a good citizen" and unload the one that had the button to begin with?
Quote this message in a reply
Posts: 86
Joined: 2008.04
Post: #2
To inject a new view into the layer stack, you can manually allocate and add a view from an action in the RootController :

MySubViewController *mySubView = [[MySubViewController alloc] initWithNibName:@"MySubViewController" bundle:nil];
[self.view addSubview:mySubView.view];
Quote this message in a reply
Posts: 283
Joined: 2006.05
Post: #3
Usually you'd use a navigation controller for something like this. Then use the push/pop view controller methods. This handles transitions and so on for you.

The default behaviour of view controllers is to release their view when they receive a low memory warning. This keeps navigation snappy by keeping them around when possible. Just make sure the view can be recreated without any problems.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Switching to another EAGLView help. jeonghyunhan 2 3,565 Jul 6, 2009 11:37 PM
Last Post: AnotherJake
  View is not switching jeonghyunhan 9 5,995 Mar 10, 2009 03:13 PM
Last Post: maximile