Zoltan Varadi
Zoltan Varadi

Reputation: 2488

iOS presented UINavigationController gets dismissed after it performs a popViewController

In my app i present a UINavigationController modally with a UIViewController as its rootViewController. I do it in form style. I added a second UIViewController which is also in form style and i can push to it fine. However when i perform a popViewController action after the second UIViewcontroller gets popped onto the first, the whole modally presented UIViewController gets dismissed. However i don't perform any dismissing and the dismissing function doesn't get triggered by accident either.

Any ideas why it's happening?

Sincerely,

Zoli

EDIT:

That's how i'm presenting the modal viewcontrollers with a navcontroller:

if(!welcomeScreenAlreadyPresented) {

    welcomeScreenViewController = [[WAWelcomeViewController alloc]init];
}

welcomeScreenNavController = [[UINavigationController alloc]initWithRootViewController:welcomeScreenViewController];
[welcomeScreenNavController setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[welcomeScreenNavController setModalPresentationStyle:UIModalPresentationFormSheet];
[welcomeScreenNavController setNavigationBarHidden:YES animated:NO];

[self.navigationController presentViewController:welcomeScreenNavController animated:YES completion:nil];

That's how i'm navigation in WAWelcomeViewController.m

registerViewController = [[WARegisterViewController alloc]init];

[self.navigationController pushViewController:registerViewController animated:YES];

And in WARegisterViewController.m that's how i pop back

[self.navigationController popViewControllerAnimated:YES];

Upvotes: 0

Views: 891

Answers (1)

David Ganster
David Ganster

Reputation: 1993

What you need to do is put the viewController you want to push inside another UINavigationController.

registerViewController = [[WARegisterViewController alloc]init];
UINavigationController *modalNavigationController = [[UINavigationController alloc] initWithRootViewController:registerViewController]; // autorelease if you are not using ARC

[self presentViewController:navController animated:YES completion:^{}];

You might want to add the modalNavigationController as a property to later call popViewControllerAnimated: on it.

Upvotes: 1

Related Questions