How to detect when the "Back" button is clicked in a UINavigationController

Hello All,

I have an app that has 2 screens in it. When a button is clicked on the first screen, the UINavigationController pushes the next view controller onto the stack. When I click the “Back” button on the 2nd view controller, I want to pass some information back to the 1st view controller.

The problem is that I don’t know how to detect that the “Back” button was selected on the 2nd view controller.

How do I accomplish this?


You can receive a call from the Navigation Controller -

func navigationController(UINavigationController, willShow: UIViewController, animated: Bool)

if you set the object where you want to take the action as delegate. If willShow is the view controller whose information you need to update then you know you are going back to it.