Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically creating UINavigationController in iOS

I am new to iOS. And I want to use navigation controller in my application but I have no any idea how to do it. So can any one guide me step by step for creating navigation in my application.

like image 393
user3418619 Avatar asked Apr 10 '14 07:04

user3418619


1 Answers

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

like image 101
Bhanu Avatar answered Oct 21 '22 04:10

Bhanu