0

I want to dismiss all child views and finally move to root view controller. I used the following code

DispatchQueue.main.async {
        appDelegate.window?.rootViewController?.dismiss(animated: false, completion:nil)
}

But issue is that while moving to root view , it showing child view first then root view .

How can i solve the issue? any idea?

shamly
  • 21
  • 4

2 Answers2

0

Use popToRootViewController method of navigation controller object.

ex: [self.navigationController popToRootViewControllerAnimated:YES];

This method will pop to the root view controller by popping all the view controller in between the current view controller to root view controller.

jegadeesh
  • 875
  • 9
  • 22
  • Moving to root view is working perfect , but don't know why it showing child view first then root view. – shamly May 30 '17 at 07:14
0

Use this it will dismiss all presented UIViewController's and go to rootViewcontroller

self.view.window!.rootViewController?.dismiss(animated: false, completion: nil)

And if you call it from somewhere else, you would need to pass the controller and replace self with the controller

Bala
  • 1,224
  • 1
  • 13
  • 25
  • Actually i have 2 child views and one root view. i called the dismiss from top of second child. So it shows first child then after it shows root view. Don't know why it shows this intermediate child window instead of direct root window – shamly May 30 '17 at 07:30
  • View or ViewController? – Bala May 30 '17 at 07:45
  • I mean viewcontroller – shamly May 30 '17 at 07:48
  • Okay ... Try this ... `self.presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)` – Bala May 30 '17 at 07:54