Make that tab use a custom subclass of UIViewController. (Or whatever parent class you’re using). Implement viewWillDisappear(_ animated: Bool)
. Put the code you want to execute in that method.
1
solved iOS Development – Executing Code After Leaving a tab in a tabbed application [closed]