0
votes

I'm having troubles with an UINavigationController which viewControllers property is null after tapping Back on a previously pushed view controller.

The root view controller in AppDelegate is defined with that code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];

    StartViewController *startVc = [[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:startVc];
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

At StartViewController I'm hiding the navigation bar within - (void)viewWillAppear:(BOOL)animated where I've also a UIButton instance where I push the next view controller when tapping with that code:

- (IBAction)buttonTapped:(id)sender {

    PhilosophyViewController *philsophyVc = [[PhilosophyViewController alloc] initWithNibName:@"PhilosophyViewController" bundle:nil];
    [self.navigationController pushViewController:philsophyVc animated:YES];
}

I'm heading over to the next view as expected. But when tapping the Back button at the navigation bar, the previous view (StartViewController) is empty and when checking the viewControllers property of the navigation controller - it is null?

Any idea?

Thanks in advance.

1
Do you have the back button connected up to an IBAction?, if so, what is the code you are using to move back?Jim Tierney
I would also recommend checking the value of the self.navigationController after going back. Just because self.navigationController.viewControllers is nil does not necessarily mean that navigationController is not nil.Craig Otis
There's nothing wrong with the code you posted, so the problem must be elsewhere. Are you using a storyboard at all, or only xibs? Also, where are you checking the viewControllers property?rdelmar
@Jeely The back button is currently not connected to an IBAction. @CraigOtis I've to check that. @rdelmar Only xibs - no storyboard. I'm checking the property at viewWillLoad in StartViewController code.thedom
I tried also the code from @Jeely for heading back. The view itself is empty but the title in the navigation bar is here.thedom

1 Answers

0
votes

The back button of the pushed viewController can be hooked up to an IBAction

 -(IBAction)backButtonPressed:(id)sender{

 [self.navigationController popViewControllerAnimated:YES];

}

This should pop you back to the previous view controller front the stack.

Hope this helps.