0

When dismissing a UIViewController via the back button, are there any events that I can trap?

I want to write a couple of user defaults when the UIViewController is exiting.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Scott
  • 1,370
  • 2
  • 9
  • 16
  • I would suggest you read this Apple [documentation](https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html) regarding view lifecycle. – Ozgur Vatansever Jun 25 '15 at 02:52

2 Answers2

1

Both the methods viewWillDisappear and viewDidDisappear should be called at this time.

Acoop
  • 2,586
  • 2
  • 23
  • 39
-1

willMoveToParentViewController might be your friend here

Detecting when the 'back' button is pressed on a navbar

Community
  • 1
  • 1
Mikael
  • 2,355
  • 1
  • 21
  • 45
  • "When dismissing a UIViewController via the back button" in this specific case, using willMoveToParentViewController is a way to go, it's a well-known solution. http://stackoverflow.com/questions/8228411/detecting-when-the-back-button-is-pressed-on-a-navbar/17551952#17551952 – Mikael Jun 25 '15 at 06:32
  • Then you should explain that in your answer - What you have here is more suited as a comment – Paulw11 Jun 25 '15 at 09:54
  • No, -1 is for poor answers – Paulw11 Jun 25 '15 at 12:41
  • Ok, that makes sense then. Thanks for your comment, I hope that in the end the answer will help Scott – Mikael Jun 25 '15 at 12:53