Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone SDK - Add a UINavigationController Programmatically

I have an iPhone project which currently does not have a UINavigationController in it. Instead I swap views by handling the view hierarchy myself. However - as you're probably aware - this is bad practice, so I am trying to figure out how to implement a UINavigationController into my current app. I can obviously start my project over and use an Xcode template, but I really don't want to do this.

There must be a way to do this programmatically. But I can't figure out what code needs to go in the AppDelegate. Does anyone have any experience with this? I am at a loss at the moment.

Cheers, Brett

like image 782
Brett Avatar asked Nov 15 '11 00:11

Brett


1 Answers

Yeap.

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{
   navController=[[UINavigationController alloc] init];
   MyViewController *firstController=[[MyViewController alloc] init];
   [navController pushViewController:firstController animated:NO];
   [window addSubview: navController.view];
} 
- (void) dealloc
{
   ...  
   [navController release];
   ...
}

It's a quite common question, have a look at this too.... Programmatically add UINavigationController in UIViewController

like image 129
Sr.Richie Avatar answered Sep 28 '22 12:09

Sr.Richie