在我的应用程序中,我通过以下方式回到 rootViewController:
self.navigationController?.popToRootViewController(animated: true)
现在我只想在我回来使用 popToRootViewController 时从我的 rootViewController 调用一个函数。这有可能吗?
最佳答案
最简单的方法是在调用 popToRootViewController(animated:)
之前通过 navigationController.viewControllers[0]
获取对 Root View Controller 的引用,在其上设置一个 bool 标志,然后在 Root View Controller 的 viewDidAppear
中使用该标志的值。
或者,您可以对 UINavigationControllerDelegate.navigationController(_:didShow:animated:)
使用相同的方法,但我不完全确定在以编程方式弹出 Controller 后是否会调用它。
关于iOS swift popToRootViewController 在 rootViewController 中触发函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41556496/