The navigation controller is always zero

I imagine UIViewControllerhow:

UIStoryboard *storyboard  = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

PhotoViewController *resultVC = [storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([PhotoViewController class])];
[self.navigationController presentViewController:resultVC animated:YES completion:^{}];

I registered the console, and the result is:

po self.navigationController
<UINavigationController: 0x9c3e920>

But when I'm in class PhotoViewController, I registered the console, and the result:

po self.navigationController
nil

its zero is here. I do not know why this is happening. I also have this one, but its zero is always:

[self presentViewController:resultVC animated:YES completion:^{}];
+3
source share
3 answers

Yes, this is zero. UIViewController.navigationControllerthe property will be set only if ViewControllerclicked, and not presented. The not-so-elegant solution is that you make a global link (for example, put the link in a singleton) to NavigationControllerbefore you submit it, then you can read it from the inside UIViewController.

+6
source

, navigationController.

: [self.navigationController presentViewController:resultVC animated:YES completion:^{}]; [self.navigationController pushViewController:resultVC animated:YES];

0

private navigationController ( nav), , :

self.nav = [[UINavigationController alloc] initWithRootViewController: self];

[[[UIApplication sharedApplication] delegate] window].rootViewController = self.nav;

view controller navigationController

[self.nav pushViewController: vc animated: YES];

!

nav

0

All Articles