Search code examples
iosswiftuiviewuinavigationcontroller

Swift iOS , call function after popToRootViewViewController


This is a very simple and straightforward question but I can't seem to phrase it correctly to find what I'm looking for.

I'm currently using a navigation controller. The navigation controller has a root view and two views pushed on top of that root view.

I'm using

_ = navigationController?.popToRootViewController(animated: true)

to pop those two views and go back to my root view.

I would like to call a function after transitioning back to my main view. Is there a function that I can override in my root view to do that?

Thanks a lot!


Solution

  • You could override the viewDidAppear / viewWillAppear and use the isBeingPresented property

    You can check here for an example

    https://stackoverflow.com/a/31612271/2585955