prepareForSegue is called only in the forward direction. It is not called when you relax. To process unwinding segments, you need to connect the exit button to the IBAction method, which takes the segue parameter as a parameter. This method will be called when you relax.
This post contains more information on how to use them.
source share