简体   繁体   English

将以模态形式呈现的视图控制器转移给其他基础视图控制器

[英]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.

相关问题 关闭从模态呈现的视图控制器翻转的视图控制器 - Dismiss view controller flipped from modally presented view controller 关闭以模态显示的视图使标签栏控制器(种类)重置 - Dismiss Modally presented view makes tab bar controller (kind of) reset 将数据传递给视图控制器时,以模态方式呈现该控制器时是否有所不同? - Passing data to a view controller different when the controller is presented modally? 只要下一个模态显示,就会关闭或删除以前模态显示的视图控制器 - Dismiss or remove previous modally presented view controller as soon as the next one appear modally 在以模态表示的View Controller上调用viewDidLoad - Calling viewDidLoad on a View Controller presented Modally willRotateToInterfaceOrientation未在模态呈现的视图控制器中调用 - willRotateToInterfaceOrientation not being called in a modally presented view controller 模态显示/关闭视图控制器时通知? - Notification when view controller is presented modally/dismissed? 从模态呈现的视图控制器导航到根视图控制器 - Navigate to root view-controller from modally presented view controller 取消双模态呈现视图控制器的父视图控制器 - Dismissing parent view controller of double modally presented view controller 动画根视图 controller 嵌入到导航 controller 以模态方式呈现 - Animate root view controller embedded into a navigation controller presented modally
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM