Programmatically creating UINavigationController in iOS

In appDelegate.h

@property (strong, nonatomic) UINavigationController *navController;

and set the delegate UINavigationControllerDelegate and synthesise object in appDelegate.m now,

appDelegate.m

you can set navigation controller in didFinishLaunchingWithOptions method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    frstVwCntlr = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];
    self.navController = [[UINavigationController alloc] initWithRootViewController:self.frstVwCntlr];
    self.window.rootViewController = self.navController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

In the above code , your firstViewController is set to UINavigationController and UINavigationController added to UIWindow like

self.window.rootViewController = self.navController

Hope this may help you


If you want to create everything programmatically you have to do it in AppDelegate.

But if you don't want to do it programmatically, then just select the ViewController in Storyboard then select menu options:

Editor > Embed In > Navigation Controller