从第四个视图控制器的第三个转到根视图控制器 swift [英] Go from third of forth view controller to root view controller swift
问题描述
我有 3 个视图控制器,以模态方式呈现,如何关闭视图控制器并直接从第三个右侧返回到第一个(根)视图控制器.
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.
基本上,当我从第三个调用 dismissViewControllerAnimated
时,我希望它也关闭底层的第二个视图控制器并直接返回到第一个视图,从内存中释放其他视图.
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.
编辑
简单地说,想从右侧的第三个视图返回到第一个视图,而不必经过并关闭中间的视图.显然我不能只呈现第一个和第三个,因为那会造成大量内存泄漏.
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.
推荐答案
为此使用 NSNotificationCenter
.当您想关闭所有视图控制器时,您可以发布通知:
Use NSNotificationCenter
for that.
You can post a notification when you want to dismiss all of your view controllers:
NSNotificationCenter.defaultCenter().postNotification("dismissNotification")
然后让这些视图控制器注册以在您的 viewWillAppear
函数中监听此类通知:
Then make these view controllers register to listen for such notifications in your viewWillAppear
function:
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("dismissFunction"), name: "dismissNotificaiton", object: nil)
最后,您在 dismissFunction
self.dismissViewControllerAnimated(true, completion: nil)
这篇关于从第四个视图控制器的第三个转到根视图控制器 swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!