Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7590123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:19:42+00:00 2026-05-30T20:19:42+00:00

I have a game with two rootViewControllers – one for the Menu and the

  • 0

I have a game with two rootViewControllers – one for the Menu and the other for the Game itself.

When the user switches between the Game and the Menu, I want to switch the rootViewController. Ultimately my questions is, what is the best way to do this? Or is there another approach for switching stacks that makes more sense than having 2 rootViewControllers?

As it stands, I have an instance of a navigationController in my appDelegate. When I want to switch rootViewController, I initialise a new navigationController, set it’s rootVC, then set this to the instance of the navController in the appDelegate. The code to transition from the menu to the game looks like this:

//Initialise the new Root Controller
GameViewController *rootController = [[GameViewController alloc] init];

UINavigationController *newNavController = [[UINavigationController alloc] initWithRootViewController:rootController];
[rootController release];   
newNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newNavController animated:YES];

//Setting the appDelegate's navController to the new navController allows the menu to dealloc. 
//This must happen AFTER the newNavController has been loaded. 
MiniAppDelegate *appDelegate = (MiniAppDelegate *)[[UIApplication sharedApplication] delegate]; 
appDelegate.navController = newNavController;
[newNavController release];

Is this bad practice?? I have an issue with my app when it resumes from background and I think this might be what’s causing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:19:43+00:00Added an answer on May 30, 2026 at 8:19 pm

    You might be going well by not presenting a modal view controller, but to use a UIViewController that manages the underlying view controllers.

    Similar to this:

    // MainNavigationController extends UINavigationController
    
    @property (nonatomic,retain) UIViewController childViewController
    
    -(void)viewDidLoad {
        self.childViewController = [MenuViewController alloc] initWithNibName...];
        [self pushViewController:childView...];
    }
    
    -(void)launchGame {
        self.childViewController = [GameViewController alloc] ... ];
        self.viewControllers = [NSArray array];
        [self pushViewController:childView...];
    }
    

    This way you hold a reference to your current view controller all the time and manage the displaying of them in one place.

    You should also pass both child view controllers a reference to the MainNavigationController so that you can use delegate methods.

    edit:

    To clarify things a bit regarding the first comment: Yes, the MainNavigationController is the starting point of your app which handles the displaying of the menu and the game itself.

    The line self.viewControllers = [NSArray array] is used to just empty out the list of current view controllers when launching a game. This is done to replace the menu with the game instead of just pushing it. This way, you don’t have 8 view controllers when the user goes to the menu, to the game, to the menu and so on.

    A similar method would be used to open the menu while playing the game: A button would ask the MainViewController to open the menu. You can either to it the same way the launchGame method works or you can then present it the modal way to keep the game state or you put a smaller in-game menu before that or whatsoever – many ways to handle things from there on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two buttons on my application. One button starts a new Game (lets
I'm developing a game. I want to have game entities each have their own
I have an game application I have written for Windows Mobile and I want
I have a game object which processed in two completely different places. In Contact
I have a simple iPhone game consisting of two threads: the main game loop
I have a Silverlight game controlled by the keyboard, and I want it to
I'm programming an online game for two reasons, one to familiarize myself with server/client
I currently have a GAME table with two fields user_id, win win = 1
Im programming a little game where two Players have to click some Buttons it
I have a 2D game that uses two integer arrays to track x and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.