How to add navigation controller programmatically?

后端 未结 2 596
南旧
南旧 2021-01-03 08:12

I use code below, but it is not loaded:

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@\"Main\" bundle:nil];
self.mapViewController = [storybo         


        
相关标签:
2条回答
  • 2021-01-03 08:55

    try as below

    UIViewController *bbp=[[UIViewController alloc]initWithNibName:@"UIViewController" bundle:nil];
    UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
    // [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
      [self.navigationController pushViewController:passcodeNavigationController animated:YES];
      [passcodeNavigationController release];
    
    0 讨论(0)
  • 2021-01-03 08:59

    Add this code to your AppDelegate.m in the didFinishLaunchingWithOptions function:

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"YOUR_STORYBOARD_NAME" bundle:nil];
    yourViewControllerClassName *vc = [sb instantiateViewControllerWithIdentifier:@"YOUR_VIEWCONTROLLER_ID"];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    

    yourViewControllerClassName is the .h and .m file name that is linked to your viewController.

    YOUR_STORYBOARD_NAME is the name of your .storyboard file. For example, fill in Main if your .storyboard file is called Main.storyboard.

    YOUR_VIEWCONTROLLER_ID is the ID for your veiwController. You can edit it in the Identity inspector.(See photo)

    Hope this helps:)

    0 讨论(0)
提交回复
热议问题