Reputation: 681
In my app I go back to rootViewController via:
self.navigationController?.popToRootViewController(animated: true)
Now i want to call a function from my rootViewController only when i come back using popToRootViewController. Is there a possibility for this?
Upvotes: 0
Views: 661
Reputation: 10716
The easiest way to go about it is to get a reference to the root view controller via navigationController.viewControllers[0]
before the call to popToRootViewController(animated:)
, set a boolean flag on it and then use the value of that flag in the root view controller's viewDidAppear
.
Alternatively, you could use the same approach with UINavigationControllerDelegate.navigationController(_:didShow:animated:)
, though I'm not entirely sure whether it will be called after popping the controllers programmatically.
Upvotes: 1