This question has been asked before, but the answered ones I could find were from 2009 and don't suit my problem. Let me reiterate the issue.
I have a UINavigationController
that spawns and pushes lots of different UIViewController
s onto its stack. One of those deals with some Core Data operations that need to be saved when that one particular VC get's popped off the stack. Don't focus on the Core Data part, it's about the popping.
How can I hook into the moment that the UIViewController
is going to be popped off the stack?
- I was hoping for a delegate method of some sort, but couldn't find it. The
UINavigationControllerDelegate
protocol is very sparse. - I then started thinking of using
viewWillDisappear
, but that one is also called if another view is pushed onto the stack, so it doesn't provide the right moment. - This answered question, from 2009, opts to look at the
viewWillAppear
of the view controller that we're 'popping to', but since that call doesn't have a reference to the VC that needs to do the checking, this is unsatisfactory and will introduce a level of dependency that is counter productive (the VC is used by several NCs). - Another answered question, also from 2009, opts to subclass UINavigationController and rewrite the popViewControllerAnimated: method. Or alternatively use the VC's dealloc. My gut tells me that can't be the way to go.
- Finally there's one last recent question from march 2011, but no one cared to answer it.
That leaves me in my current unsatisfied state of mind. Is there anyone out there with a better solution to finding the moment your UIViewController is popped off a UINavigationController's stack?
Cheers,
EP.