导航后无法删除 child viewcontroller

Unable to remove child viewcontroller after Navigation

我在 VC1 中添加了 child viewcontroller。在 child viewcontroller 中点击一个按钮,我将推到另一个 viewcontroller ,VC2。在 VC2 中点击后退按钮,我需要删除 child viewcontroller 但我无法执行 it.Can 你能帮帮我吗?

override func viewDidDisappear(_ animated: Bool) {

        let controller = storyboard!.instantiateViewController(withIdentifier: "PopupViewController") as! PopupViewController
        controller.willMove(toParentViewController: nil)
        controller.view.removeFromSuperview()
        controller.removeFromParentViewController()
 }

我在 VC1 中添加了以下内容,它解决了我的问题

override func viewWillDisappear(_ animated: Bool) {

    for controllers in self.childViewControllers
    {
        controllers.willMove(toParentViewController: nil)
        controllers.view.removeFromSuperview()
        controllers.removeFromParentViewController()
    }

}