Kyle Goslan
Kyle Goslan

Reputation: 10930

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.

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.

enter image description here

Upvotes: 3

Views: 1230

Answers (2)

Dani
Dani

Reputation: 1288

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)

Upvotes: 1

Roi Mulia
Roi Mulia

Reputation: 5896

Try this :

self.dismissViewControllerAnimated(true, completion: nil)

Let me know if that what you needed :)

Upvotes: 0

Related Questions