如何dismiss多个viewController

如何dismiss多个viewController(当然是建立在已经连续present多个controller的前提下)

今天才真正认识dismissViewControllerAnimated这个方法:

举个例子:

A->B->C->D (->代表present,当前页面是D)

如果想回到B

用[B dismissViewControllerAnimated:YES completion:nil]

这样调用,只会最上面的D会以动画的方式消失,其他中间的C从堆栈中删除,达到回到B的效果。

如何在D获取到B?
D的presentingViewController是C,C的presentingViewController是B,
所以
在D页面的时候
C= D.presentingViewController;
B = C.presentingViewController;

UIViewController *parentVC = self.presentingViewController;

再举个例子A->B

dismissViewControllerAnimated 其实是prespresenting view controller(A)用这个方法来dissmiss B的,而我们平时经常在B页面使用用[self dismissViewControllerAnimated:YES completion:nil];(self是B),其实UIKit会要求A处理这个dismiss。

原文:

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值