TheRealRonDez
TheRealRonDez

Reputation: 2807

How to return to Root View Controller

I am currently working on an app which presents a screen modally and another custom progress indicator modally. Is it possible to return to the root View Controller seamlessly?

Home -> screen1-> screen2(Custom progressIndicator)

I want to dismiss the custom progressIndicator (and the screen presented modally) and return to my home (root) View Controller in one go.

 self.navigationController?.popToRootViewControllerAnimated(true)

Thank you for the help!

Upvotes: 6

Views: 15480

Answers (4)

Dnyaneshwar Shinde
Dnyaneshwar Shinde

Reputation: 187

Swift 4

self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);

Upvotes: 3

Oskar
Oskar

Reputation: 2562

In Swift 3 this will work:

self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);

Upvotes: 0

Yuchao Zhou
Yuchao Zhou

Reputation: 1072

If you use presentViewController, you can use

[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];

to go back to root view. It works on IOS9.

Upvotes: 9

Pankaj Teckchandani
Pankaj Teckchandani

Reputation: 745

You need to dismiss presented model then you can pop all the pushed view controllers. As presented model would not be in the stack of the navigation.

self.dismissViewControllerAnimated(true, completion: {});

Then you can pop to base view controller.

self.navigationController.popViewControllerAnimated(true);

Upvotes: 11

Related Questions