Programmatically creating UINavigationController in iOS

前端 未结 7 2205
孤街浪徒
孤街浪徒 2020-12-09 22:54

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

7条回答
  •  情书的邮戳
    2020-12-09 23:09

    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

提交回复
热议问题