user1686342
user1686342

Reputation: 1345

Navigation controller is nil in the second view controller

So I've setup the AppDelegate to load a root view vc which has a navigation controller:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SecondViewController *vc = [[SecondViewController alloc] init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:vc];
[self.window makeKeyAndVisible];
return YES;

In my SecondViewController I have a method that then calls a push to present the third view controller:

ThirdViewController *thirdVC = [[ThirdViewController alloc]init];
[self.navigationController pushViewController: thirdVC animated:YES];

Although this doesn't work. On closer inspection the self.navigationController property on the SecondViewController is nil. Is there something I've missed on the AppDelegate to make this non-nil?

Upvotes: 0

Views: 731

Answers (2)

Avinash Mishra
Avinash Mishra

Reputation: 797

Try this as i was facing same issue but i resolved it by setting same class name and Storyboard ID name under The Custom Class header of your project.

registerViewController *regVC = [self.storyboard instantiateViewControllerWithIdentifier:@"registerViewController"]; [self.navigationController pushViewController:regVC animated:YES];

Upvotes: 1

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

Try this:

SecondViewController *vc = [[SecondViewController alloc] init]; 
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];

THere is no need of making the root view controller nil in the app delegate.

Upvotes: 0

Related Questions