我已经将一个子视图控制器添加到VC1。在点击子视图控制器中的按钮时,我正在推送到另一个视图控制器VC2。在VC2中点击后退按钮时,我需要删除子视图控制器,但我无法做到。你能帮我吗?
override func viewDidDisappear(_ animated: Bool) {
let controller = storyboard!.instantiateViewController(withIdentifier: "PopupViewController") as! PopupViewController
controller.willMove(toParentViewController: nil)
controller.view.removeFromSuperview()
controller.removeFromParentViewController()
}
答案 0 :(得分:1)
我在VC1中添加了以下内容,它解决了我的问题
override func viewWillDisappear(_ animated: Bool) {
for controllers in self.childViewControllers
{
controllers.willMove(toParentViewController: nil)
controllers.view.removeFromSuperview()
controllers.removeFromParentViewController()
}
}