0
votes

In my app, I've got a mainViewController that I'm trying to use for holding and controlling a couple of main view for my app. I first loaded up a splash screen, but then am wanting to have it so that when a user taps on the splash screen, they are taken to the main menu.

I've got the splash screen part working fine, but I'm having trouble with the NavigationController part.


[splashView.view removeFromSuperview];

mainMenu = [[menuScreenViewController alloc] initWithNibName:@"menuScreenViewController" bundle:nil]; mainMenu.title = @"Menu"; mainNavController = [[UINavigationController alloc] init]; [mainNavController pushViewController:mainMenu animated:NO];

[MAINVC.view addSubview:mainNavController.view];

[mainMenu release]; [mainNavController release];

[splashView release];


(MAINVC is defined elsewhere to be my main view controller).

Anyway, when I do this, I get the navigation controller with the title 'Menu', but the view contained in the mainMenu view controller do not show up in the navigation controller.

If I simply add the mainMenu's view ass a subview of MAINVC.view, it shows up correctly.

Any suggestions on how to get it to show up in my navigation controller?

1
avery, did this answer help at all?Sam Ritchie

1 Answers

0
votes

avery, you're going to need to initialize the navigation controller with the mainMenu as its root view controller, instead of just initializing and then pushing a new view on. It needs that root view controller to work.

mainMenu = [[menuScreenViewController alloc] initWithNibName:@"menuScreenViewController" bundle:nil];
mainMenu.title = @"Menu";
mainNavController = [[UINavigationController alloc] initWithRootViewController:mainMenu];

//ADD MODAL SPLASH SCREEN HERE

[MAINVC.view addSubview:mainNavController.view];

[mainMenu release];
[mainNavController release];

[splashView release];

As the comment above shows, I'll suggest that you initialize this way, and then then add your splash screen to the nav controller as a modalViewController. This will prevent any delay you might have from the mainMenu initialization, when you tap the touchscreen. Then, when the modal view receives a touch, you can call:

[self.parentViewController dismissModalViewControllerAnimated:YES];