Checking if a UIViewController is about to get Popped from a navigation stack?

iphone, objective-c, uikit, uinavigationbar, uiviewcontroller

Solution

I don't think there is an explicit message for this, but you could subclass the UINavigationController and override - popViewControllerAnimated (although I haven't tried this before myself).

Alternatively, if there are no other references to the view controller, could you add to its - dealloc?

Problem

I need to know when my view controller is about to get popped from a nav stack so I can perform an action. I can't use -viewWillDisappear, because that gets called when the view controller is moved off screen for ANY reason (like a new view controller being pushed on top). I specifically need to know when the controller is about to be popped itself. Any ideas would be awesome, thanks in advance.

Original source