简体   繁体   English

从第四个视图控制器转到根视图控制器swift

[英]Go from third of forth view controller to root view controller swift

I have 3 view controllers, presented modally, how do I dismiss the view controllers and go directly from the third right back to the first (root) view controller. 我有3个视图控制器,以模态方式呈现,如何解除视图控制器并直接从第三个右侧返回到第一个(根)视图控制器。

Basically, when I call dismissViewControllerAnimated from the third I want it to also dismiss the underlying second view controller and return straight to the first view, releasing the others from memory. 基本上,当我从第三个调用dismissViewControllerAnimated ,我希望它也消除底层的第二个视图控制器并直接返回到第一个视图,从内存中释放其他视图。

EDIT 编辑

Simply, want to go from the third view on the right, back to the first without having to go through and dismiss the middle on. 简单地说,想要从右边的第三个视图,回到第一个视图,而不必经过并解雇中间。 Obviously I can't just present the first one form the third, as thats a massive memory leak. 显然,我不能只提出第三个形式,因为这是一个巨大的内存泄漏。

在此输入图像描述

Use NSNotificationCenter for that. 使用NSNotificationCenter You can post a notification when you want to dismiss all of your view controllers: 您可以在要关闭所有视图控制器时发布通知:

NSNotificationCenter.defaultCenter().postNotification("dismissNotification")

Then make these view controllers register to listen for such notifications in your viewWillAppear function: 然后让这些视图控制器注册以在viewWillAppear函数中侦听此类通知:

 NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("dismissFunction"), name: "dismissNotificaiton", object: nil)

Finally, you call dismissViewController: in your dismissFunction 最后,在你的dismissFunction调用dismissViewController: .

self.dismissViewControllerAnimated(true, completion: nil)

Try this : 尝试这个 :

self.dismissViewControllerAnimated(true, completion: nil)

Let me know if that what you needed :) 让我知道你需要什么:)

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

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