[英]dismiss a modally presented view controller to a different underlying view controller
I have a UIViewController that's embedded in a Navigation View Controller. 我有一个嵌入在导航视图控制器中的UIViewController。 I then modally present another view controller that shows a countdown. 然后,我模态呈现另一个显示倒计时的视图控制器。 Once the countdown ends, the modal view controller should be dismissed and show a different underlying view controller from the original presenting UIViewController. 倒数结束后,应该关闭模式视图控制器,并显示与原始呈现的UIViewController不同的基础视图控制器。
Does anyone know how to do this in ios8 with Swift? 有谁知道如何在iOS8中使用Swift做到这一点?
There are different ways to approach this. 有多种方法可以解决此问题。 One way is to replace the initial presenting view controller with the desired underlying one when you present the modal view controller. 一种方法是在呈现模式视图控制器时,用所需的基础视图控制器替换初始呈现视图控制器。
NSArray * viewControllers = [self.navigationController viewControllers];
[viewControllers replaceObjectAtIndex:viewControllers.count - 1 withObject:replacementController];
Dismissing the modal will simply show the different underlying view controller that was already swapped. 取消模态将仅显示已交换的其他基础视图控制器。
when you do popViewController
from stack there is a handler. 当您从堆栈执行popViewController
,将有一个处理程序。 This will be called at the end of this function so you can pass a block where you can presentViewController
or make change to the current one. 该函数的末尾将调用此方法,因此您可以传递一个代码块,在该代码块中您可以presentViewController
或更改当前presentViewController
块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.