0
[A] -> Show Segue -> [B]

Everything is inside a navigation controller. When the user pushes the back button on "B", how can it know? I want to perform an action (save profile) immediately when the user pushes back.

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

1 Answers1

0

The UIViewController class has a function called willMoveToParentViewController. I would try using that to accomplish what you're trying to accomplish.

override func willMoveToParentViewController(parent: UIViewController?) {
    print("back button was pressed")    
    saveMyProfile()
}

Something like that should hopefully do the trick.

user3353890
  • 1,844
  • 1
  • 16
  • 31
  • 1
    This method is called when a view controller is added to another view controller and when it is removed from another view controller. – rmaddy May 23 '16 at 03:14
  • he could check for isBeingDismissed, and only save when the viewController is being dismissed. – user3353890 May 23 '16 at 03:17
  • `isBeingDismissed` can't be used inside `willMoveToParentViewController`. – rmaddy May 23 '16 at 03:18
  • well what about if parent.isBeingPresented == true ....that way you're checking against the given parent variable – user3353890 May 23 '16 at 03:19
  • `isBeingPresented` can't be used inside `willMoveToParentViewController`. – rmaddy May 23 '16 at 03:22
  • you can use it inside `willMoveToParentViewController` i just tried it – user3353890 May 23 '16 at 03:29
  • The documentation states it is only valid inside `viewWill|DidAppear`. Perhaps `willMoveToParentViewController` is being called from inside those methods. – rmaddy May 23 '16 at 03:32