从Modal中关闭View Controller

时间:2017-05-12 12:15:38

标签: ios swift dismiss navigationcontroller

我有一个带有多个控制器的MainTabBarController。 在我的FirstTabViewController(嵌入UINavigationController)中,我推送到另一个视图控制器,例如:navigationController?.pushViewController(secondViewController, animated: true)

在这个控制器中,我要显示一个模态视图控制器,如:

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)

SomeViewController中,我要将此控制器视为:self.dismiss(animated: true),但它会自动弹出到根视图控制器(FirstTabViewController)。

我的问题,为什么?

感谢。

1 个答案:

答案 0 :(得分:2)

在您当前的控制器上显示SomeViewController而不是navigationController

改变了行:

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

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