viewWillAppear not being called after popToRootViewController

333 Views Asked by At

This is the flow:
VC1 ->(PUSH)-> VC2 ->(PUSH) -> VC3
When clicking a button in VC3 I am calling the method below and it works properly - taking me back to VC1:

self.navigationController?.popToRootViewController(animated: false)

But the problem is in viewWillAppear() method in VC1 which is not being called.
Is there any solution to call it?

2

There are 2 best solutions below

0
On

i am not exactly sure but viewWillAppear() will called while loading controller. it's not calling while dismiss other controller.so, you need to try custom Delegate or Notification observer.

0
On

You can do the trick here:

if let root = navigationController?.viewControllers.last(where: { $0 is YourRootController }) {
     navigationController?.popToViewController(root, animated: true)
}