I have a navigation controller I created in a storyboard. The forward and back functions work fine…The part I am struggling with is how I can save state of the application when the back button is pressed. Is there a way I can have my current view controller be notified when the back button is pressed?
How can I use viewWillDisappear in this case:
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.title = model.title;
readerViewController.delegate = self;
[self.navigationController pushViewController:readerViewController animated:YES];
[readerViewController release];
(I am using a pdf reader library)
Well, the view controller that is on the top of the stack (presently on screen) will get the
viewWillDisappear:andviewDidDisappear:messages.viewWillDisappear:is a good place to save anything the user may have been editing or manipulating on that screen.Edit to address your followup:
So when the user taps “back”, you’ll get these messages (I’m going to call the presenting view controller ‘rootViewController’)
So if you have access to the ReaderViewController source, you can add/edit methods for those events. You can also set a delegate on the navigation controller, and that delegate will get
navigationController:willShowViewController:animated:andnavigationController:didShowViewController:animated:as the user comes back.But if you tell us more about this “ReaderViewController”, maybe it has delegate methods you can implement to save whatever state it manipulates. What “pdf reader library” is this? And what state exactly are you trying to save?