简体   繁体   English

关闭呈现视图 controller

[英]Dismiss presenting view controller

I have the following situation:我有以下情况:

view controller A -> presents modally -> view controller B查看 controller A -> 模态显示 -> 查看 controller B

view controller B -> presents modally -> view controller C查看 controller B -> 模态显示 -> 查看 controller C

I would like to dismiss view controller "C" and go directly to "A" instead of showing "B" since it do not make sense to show "B" at that time.我想直接将视图 controller "C" 和 go 忽略为 "A" 而不是显示 "B",因为当时显示 "B" 没有意义。

How can I accomplish that?我怎样才能做到这一点?

Thanks, Daniel谢谢,丹尼尔

In 'view controller C' -> 在'视图控制器C' - >

Before iOS 6: Use 在iOS 6之前:使用

[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];

Or, 要么,

[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES];

From and Above iOS 6: Use 从iOS 6开始:使用

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];

You can use segues to present view controllers from other view controllers. 您可以使用segue从其他视图控制器呈现视图控制器。

To go backwards through a hierarchies you normally dismiss presented view controllers or you go back to specific view controllers through unwind segues . 要在层次结构中向后移动,通常会忽略显示的视图控制器,或者通过展开segues返回到特定的视图控制器。

Try the following: 请尝试以下方法:

[vcB dismissModalViewControllerAnimated:NO]   //no Animation, so happens instantly
[vcA dismissModalViewControllerAnimated:YES]  //with Animation, this is all you see  

Your best bet would be use navigation controllers if your B and C are related and are more detailed version of A 如果您的B和C是相关的并且是A的更详细版本,那么您最好的选择是使用导航控制器

A->BC . A-> BC。 You unwindsegue to unwind the stack/pop the view controllers pushed on the stack. 您将放松堆栈/弹出堆栈上推送的视图控制器。

Read this link very useful - http://chrisrisner.com/Unwinding-with-iOS-and-Storyboards 阅读此链接非常有用 - http://chrisrisner.com/Unwinding-with-iOS-and-Storyboards

This is an old question and has an accepted answer but it did not solve my problem.这是一个老问题,有一个公认的答案,但它并没有解决我的问题。 Therefore, I would like to propose another solution for those who need different approaches.因此,我想为需要不同方法的人提出另一种解决方案。

The story is A presents B, B presents C, A is shown when C is dismissed.故事是 A 呈现 B,B 呈现 C,当 C 被解雇时显示 A。 Here is my approach;这是我的方法; Present ViewB from ViewA, when it comes to presenting ViewC from ViewB, do it from ViewA, and dismiss ViewB as follows;从 ViewA 呈现 ViewB,当从 ViewB 呈现 ViewC 时,从 ViewA 执行,并按如下方式关闭 ViewB;

let presentingNavCon = navigationController?.presentingViewController as? UINavigationController
let viewC = ViewC()
navigationController?.dismiss(animated: false)
presentingNavCon?.present(viewC, animated: true)

so, when you dismiss ViewC, ViewA appears.因此,当您关闭 ViewC 时,会出现 ViewA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM