在rootViewController中的iOS swift popToRootViewController触发函数

时间:2017-01-09 20:36:12

标签: ios swift segue rootview

在我的应用程序中,我通过以下方式返回rootViewController:

self.navigationController?.popToRootViewController(animated: true)

现在我只想在使用popToRootViewController返回时从rootViewController调用一个函数。这有可能吗?

1 个答案:

答案 0 :(得分:1)

最简单的方法是在调用navigationController.viewControllers[0]之前通过popToRootViewController(animated:)获取对根视图控制器的引用,在其上设置一个布尔标志,然后使用该标志的值在根视图控制器的viewDidAppear中。

或者,您可以对UINavigationControllerDelegate.navigationController(_:didShow:animated:)使用相同的方法,但我不完全确定在以编程方式弹出控制器后是否会调用它。