如何以编程方式从堆栈中删除UViewController

时间:2018-08-23 10:49:42

标签: ios swift

我有一个带有两个视图控制器的应用程序。我能够以编程方式显示第二个视图控制器(我使用自定义弹出窗口/警报),但是无法以编程方式将其删除。我不想使用UINavigationController。

 // SHOW ALERT - UIViewcontroller - 1
 let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
 let popUp = storyboard.instantiateViewController(withIdentifier: "popupEmpty")
 self.present(popUp, animated: true, completion: nil)


 // HIDE ALERT - UIViewController -2 

let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let popUpVC = storyboard.instantiateViewController(withIdentifier: "popupEmpty")
self.navigationController?.pushViewController(popUpVC, animated: true) // ????

2 个答案:

答案 0 :(得分:2)

如果您展示一些东西,则需要关闭

self.dimiss(animated: true, completion: nil)

如果您推动,则需要弹出

self.navigationController?.popViewController(animated: true)

答案 1 :(得分:0)

在呈现ViewController以显示Alert时,应关闭ViewController。完成展示的ViewController后,编写以下代码:

dismiss(animated: true, completion: nil)