I have a stack of UIViewController
subclasses. Each modifies a NSManagedObject
model. Many of them also present their own modal view controllers.
I need to save changes to the NSManagedObjectContext
when a user either 'pops' the view controller or pushes the next view controller.
Currently, I'm hiding the default back button and setting my own UIBarButtonItem
with a target
of self
and a custom action
.
This works okay, but ideally, I want to use the default back button and run code before the pop. Is there a way I can run my own code before the pop?
(I'd prefer not to put code into viewWillDisappear
as persisting to disk can be expensive and this method can also be triggered by modals being displayed by view controller.) Can it be done?