There are three viewController, MainViewController ViewControllerB and ViewControllerC. 
MainViewController will be loaded when the app launch.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    MainViewController * main = [[MainViewController alloc]init];
    UINavigationController * navigationController = [[UINavigationController alloc]initWithRootViewController:main];
    self.window.rootViewController = navigationController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    return YES;       
}
and there is a button on the MainViewController, present ViewControllerB,
UIViewController *rootViewController = [[UIApplication sharedApplication].keyWindow rootViewController];
ViewControllerB * vcb=[[ViewControllerB alloc] init];
[rootViewController presentViewController:vcb animated:YES completion:nil];
After the ViewControllerB appear, click the button push ViewControllerC.
but the navigationController is nil. It can't push ViewControllerC
[self.navigationController pushViewController:vcC animated:YES];
                You have the MainViewController (mvc), which is embedded in a NavigationController;
Then, on mvc you have the following code:
[rootViewController presentViewController:vcb animated:YES completion:nil];
You are calling presentViewController on the current ViewController, which will modally present the next ViewController, in this case ViewControllerB (vcb);
Finally, you try to access the NavigationController inside ViewControllerB (vcb) in order to push ViewControllerC (vcc), with the following code:
[self.navigationController pushViewController:vcC animated:YES];
The problem is that vcb is not aware of the NavigationController, since presentViewController presents the view controller modally, outside the existing navigation stack. Thus, resulting in a nil NavigationController in vcb.
You can refer to https://stackoverflow.com/a/14233252/9323816 for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With