1
votes

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?

1
Hva you checked unwind segues? stackoverflow.com/questions/12561735/…Marius Waldal

1 Answers

0
votes

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.