Switching between UIViewContollers
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?
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?
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];
mySubView.view.center=CGPointMake(375,375);
[self.view addSubview:mySubView.view];
MySubViewController *mySubView = [[MySubViewController alloc] initWithNibName:@"MySubViewController" bundle:nil];
mySubView.view.center=CGPointMake(375,375);
[self.view addSubview:mySubView.view];
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.
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.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Switching to another EAGLView help. | jeonghyunhan | 2 | 2,433 |
Jul 6, 2009 11:37 PM Last Post: AnotherJake |
|
| View is not switching | jeonghyunhan | 9 | 3,594 |
Mar 10, 2009 03:13 PM Last Post: maximile |
|

