关闭视图控制器后未调用Swift viewWillAppear

时间:2018-06-28 18:06:51

标签: ios swift

我正在从称为HomeController的视图控制器中呈现一个视图控制器,如下所示:

let viewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginController") as! LoginController

let navigationController: UINavigationController = UINavigationController(rootViewController: viewController)

present(navigationController, animated: true, completion: nil)

在显示的视图控制器中,LoginController有时会被关闭:

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

但是回到HomeController时,它不是在调用viewWillAppear,我真的需要检查HomeController的返回条件,所以当LoginController取消视图时如何调用viewWillAppear?

2 个答案:

答案 0 :(得分:5)

在iOS 13中,如果您要提供视图控制器并且返回时,则不会调用viewWillAppear。 我已将其从现在更改为推送视图控制器,并且现在正在调用方法。

答案 1 :(得分:3)

您需要设置正确的presentationStyle。如果您希望presentatedController成为全屏并命名为先前的viewWillAppear,则可以使用“ .fullScreen

let viewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginController") as! LoginController

let navigationController: UINavigationController = UINavigationController(rootViewController: viewController)

navigationController.modalPresentationStyle = .fullScreen

present(navigationController, animated: true, completion: nil)