1

According to the documentation dismissViewControllerAnimated:completion: will allow you to dismiss an entire stack of view controllers by merely dismissing the controller on the bottom of the stack. When I try this, only the top controller is being dismissed.

For example, consider the figure below where controller A and B have both been presented modally. If I dismiss A then both A and B should be dismissed, but only B is being dismissed!

enter image description here

Below is the action that is trigged when the user click on B's button. The root view controller dismisses A (its presented controller), but only B is dismissed!!

- (IBAction)dissmissAandB:(id)sender {
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    ViewController *rootViewController = 
         (ViewController *) appDelegate.window.rootViewController;
    [rootViewController.controllerA dismissViewControllerAnimated:YES completion:^{}];Below
}

The root view controller's controllerA property is set when the first segue is prepared (i.e., when A is presented). Any ideas why this is not working as advertised?

wcochran
  • 8,577
  • 4
  • 48
  • 58
  • Hva you checked unwind segues? http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-to-use-them – Marius Waldal Mar 20 '14 at 20:00

1 Answers1

0

Actually, I discovered the correct call is

[rootViewController dismissViewControllerAnimated:YES completion:^{}];

instead of

[rootViewController.controllerA dismissViewControllerAnimated:YES completion:^{}];

The receiver of the method is the controller that presented the bottom controller not the bottom controller itself.

onmyway133
  • 38,911
  • 23
  • 231
  • 237
wcochran
  • 8,577
  • 4
  • 48
  • 58