2

I have a navigation based app that requires a passcode to view some pages. When I am on Controller A I want to push to the Passcode Controller then push to Controller B and remove the Passcode Controller from the stack.

So to be clear, Passcode Controller is stuck in between Controller A and Controller B and I do not know how to remove it.

I've tried two different approaches but neither is giving me the right result.

Attempt 1:

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

[self.navigationController popViewControllerAnimated:NO];

Attempt 2:

ControllerB *contB = [self.storyboard instantiateViewControllerWithIdentifier:@"contB"];

ControllerA *contA = [self.storyboard instantiateViewControllerWithIdentifier:@"contA"];

[UIView transitionFromView:contA.view
                  toView:contB.view
                  duration:0.65f
                  options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionTransitionCrossDissolve)
                  completion:^(BOOL finished){
                        self.view.window.rootViewController = contA;
                    }];

Does anyone know how I can remove Passcode Controller from the stack whenever I push Controller B from the Passcode Controller?

MSU_Bulldog
  • 3,501
  • 5
  • 37
  • 73

1 Answers1

2

Use the viewControllers property on UINavigationController, like so:

self.navigationController.viewControllers = @[ contA, contB ];

Typically, you want to execute this line after control has passed to controller B.

This question has some other code samples: Removing viewcontrollers from navigation stack

Community
  • 1
  • 1
bcholmes
  • 944
  • 1
  • 9
  • 23