0

I've a MainTabBarController with multiple controllers. In my FirstTabViewController (embed in UINavigationController) I pushed to another View Controller, like: navigationController?.pushViewController(secondViewController, animated: true).

In this controller, I've to show a modal view controller, like:

let vc = self.storyboard!.instantiateViewController(withIdentifier: "SomeViewController") as! SomeViewController

vc.modalPresentationStyle = .overFullScreen
vc.modalTransitionStyle = .coverVertical

let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true, completion: nil)

And in the SomeViewController, I've to dismiss this controller like: self.dismiss(animated: true) but it pop automatically to root view controller (FirstTabViewController).

My question, why ?

Thanks.

Idnext
  • 11
  • 1

2 Answers2

2

Present SomeViewController on your current controller not on the navigationController.

So Changed line:

self.navigationController?.present(nav, animated: true, completion: nil)

To:

self.present(nav, animated: true, completion: nil)
Nirav D
  • 71,513
  • 12
  • 161
  • 183
  • @Idnext When you present like this what happened when you dismiss the `SomeViewController` ? – Nirav D May 12 '17 at 12:25
  • The `FirstTabViewController` appear ... like a popToRoot effect – Idnext May 12 '17 at 12:26
  • @Idnext Are you sure that from firstViewController to SecondController you are moving using pushViewController because it looks like you are presenting secondViewController too instead of push – Nirav D May 12 '17 at 12:39
  • @Idnext Try once commenting these two lines `vc.modalPresentationStyle = .overFullScreen vc.modalTransitionStyle = .coverVertical` and check now it is dismissing properly ? – Nirav D May 12 '17 at 12:41
1

_ = navigationController?.popViewController(animated: true)

    dismiss(animated: true, completion: nil)