Reputation: 613
I've got an app that has 4 views; HomeView, PreGameView, GameView, PostGameView. The app works in such a way that I start on HomeView, then I click start which takes me to the PreGameView, click begin which takes me to the GameView, on end game it takes me to the PostGameView, from which I can either go back to the GameView or return to the HomeView.
I'm layering these views by using the "presentModalViewController" method. But when I layer all the way down to PostGameView and then decide to go back to the HomeView, the screen just goes white.
I've also tried dismissing each modelview before presenting the next, but that doesn't work and the app gets all confused. Does anyone know the correct way to do this? Please help?
HomeView.m
- (IBAction)loadPreGameView:(id)sender {
PreGameView *preGameView = [[PreGameView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:preGameView animated:YES];
}
PreGameView.m
- (IBAction)loadGameView:(id)sender {
GameView *gameView = [[GameView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:gameView animated:NO];
}
GameView.m
- (IBAction)loadPostGameView:(id)sender {
PostGameView *postGameView = [[PostGameView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:postGameView animated:NO];
}
PostGameView.m
- (IBAction)loadGameView:(id)sender {
GameView *gameView = [[GameView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:gameView animated:NO];
}
- (IBAction)loadHomeView:(id)sender {
HomeView *homeView = [[HomeView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:homeView animated:NO];
}
I also tried the below for my PostGameView.m, but it just showed the GameView behind it:
PostGameView.m (old)
- (IBAction)loadGameView:(id)sender {
GameView *gameView = [[GameView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:gameView animated:NO];
}
- (IBAction)loadHomeView:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
Upvotes: 0
Views: 701
Reputation: 8237
You have a chain of view controllers. You should dismiss at each level to get back up to the parent. You can also go up multiple levels and dismiss and that will pop all the children below. You might also have a memleak as you should autorelease the view controllers after you alloc them or explicitly release them.
Upvotes: 0
Reputation: 3233
A much better approach would be do use the UINavigationController to do this.
Create a UINavigationController, init with HomeView from there... [self.navigationController pushViewController:nextViewController animated:NO]
when you are done and want to POP to the beginning [self.navigationController popToRootViewControllerAnimated:NO];
the nice thing about using the NavController, is that each UIViewController will automatically have a reference to the NavController holding it, by calling self.navigationController;
you can also turn off the navigationBar if you want full screen.
also, UINavigationController retains its ViewControllers, so you should call release on any UIViewController you create, after you "push" it.
Upvotes: 1