6

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!

TheRealRonDez
  • 2,807
  • 2
  • 30
  • 40

4 Answers4

11

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);
9

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.

Yuchao Zhou
  • 1,062
  • 14
  • 19
3

Swift 4

self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);
Kalamarico
  • 5,466
  • 22
  • 53
  • 70
0

In Swift 3 this will work:

self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);
Oskar
  • 2,522
  • 32
  • 37