Programmatically build / navigate a Navigation Controller

后端 未结 2 1127
借酒劲吻你
借酒劲吻你 2020-12-16 08:32

Before:

My App is based on indepent view controllers. I can switch from one to another by replacing the root view controller on the application delegate:

         


        
2条回答
  •  别那么骄傲
    2020-12-16 09:13

    Write the following code in AppDelegate.m Class

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     {
       MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
        self.nav = [[UINavigationController alloc] initWithRootViewController:mainViewController];
        self.nav.navigationBarHidden = YES;
        [mainViewController release];
       [_window addSubview:nav.view];
       [_window makeKeyAndVisible];
     }
    

提交回复
热议问题