How to dismiss multiple viewController

How to dismiss multiple viewControllers (of course, based on the premise that multiple controllers have been continuously presented)

Today, I really learned about the dismissViewControllerAnimated method:

for example:

A->B->C->D (-> stands for present, the current page is D)

If you want to go back to B

用[B dismissViewControllerAnimated:YES completion:nil]

In this way, only the top D will disappear in an animated manner, and the other middle C will be deleted from the stack to achieve the effect of returning to B.

How to get B at D?
D’s presentingViewController is C, and C’s presentingViewController is B,
so
in the D page,
C = D.presentingViewController;
B = C.presentingViewController;

UIViewController *parentVC = self.presentingViewController;

Take another example A->B

dismissViewControllerAnimated is actually the prespresenting view controller (A) using this method to dissmiss B, and we usually use [self dismissViewControllerAnimated:YES completion:nil]; (self is B) on page B. In fact, UIKit will ask A to handle this dismiss .

original:

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

Guess you like

Origin blog.csdn.net/qq_28285625/article/details/110819204