Rut Rut - 1 month ago 4x
iOS Question

Preventing `willMoveToParentViewController` from being called when the view controller is added

In my application, when the user presses the back button on the navigation bar, I want the program to trigger some action. Therefore, I had been using

. However, the method gets called when the viewController is added or removed. What is the way to prevent it from being called when the viewController is added? If there was an alternate way to detect when the backButton in the navigationBar was pressed, please suggest it.



Use viewDidDisappear for the same. You can check the apple documentation here. This notifies the view controller when its view is removed from a view hierarchy.