Search code examples
iosipaduiviewcontrolleruinavigationcontrolleruisplitviewcontroller

Run UIViewController inside UINavigationController as a second view of UISplitViewController


I have a problem trying to access a navigation controller of the view controller from it, always returns as nill to me, though it is shown within the navigation controller. Here is what I have (I have a split view controller, that is presented as tab controller for master and viewcontroller (inside navigation controller) as detail):

FirstDetailViewController *fdvc = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailViewController" bundle:nil];
UINavigationController *fdvcNav = [[UINavigationController alloc] initWithRootViewController:fdvc];

NSArray *ipadVCs = [[NSArray alloc] initWithObjects:tabController, fdvcNav, nil];
UISplitViewController *splitvc = [[UISplitViewController alloc] initWithNibName:nil bundle:nil];
[splitvc setViewControllers:ipadVCs];
[[splitvc view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"splitViewControllerBG"]]];
[splitvc setDelegate:fdvc];

[[self window] setRootViewController:splitvc];
[[self window] makeKeyAndVisible];

But when I'm trying to access a navigation controller from the fdvc view controller in ViewDidLoad with [self navigationController] it gives me (Null) always. Thanks!


Solution

  • I fixed it. Turned out, that I had to move my code from ViewDidLoad method to ViewDidAppear and it worked fine.

    viewDidLoad is getting called before the navigationController property has been updated, that was my mistake.