Go from third of forth view controller to root view controller swift

寵の児 提交于 2019-12-12 15:40:48

问题


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.

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.

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.


回答1:


Use NSNotificationCenter for that. 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:

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

Finally, you call dismissViewController: in your dismissFunction

self.dismissViewControllerAnimated(true, completion: nil)



回答2:


Try this :

self.dismissViewControllerAnimated(true, completion: nil)

Let me know if that what you needed :)



来源:https://stackoverflow.com/questions/28161259/go-from-third-of-forth-view-controller-to-root-view-controller-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!