There are many answers but they don't answer the question. For example, I put the following code in:
override func viewWillDisappear(animated: Bool) {
if (self.navigationController!.viewControllers.indexOf(self)==nil) {
print("back button pressed\n")
}
super.viewWillDisappear(animated)
}
But 'back button pressed' gets printed to the console even when the back button has not been pressed. The scene has buttons that return to the previous scene using unwind segues, and these cause 'back button pressed' to be printed. I need to execute code only if the back button has been pressed.
Edit for Muneeba:
import UIKit
class NewViewController: UIViewController, UINavigationBarDelegate {
func navigationBar(navigationBar: UINavigationBar, didPopItem item: UINavigationItem) {
performSegueWithIdentifier("returnToStepOne", sender: self)
delegate.backFromNewViewController()
}
override func viewDidLoad() {
super.viewDidLoad()
// self.navigationController.navigationBar.delegate = self;
navigationController?.navigationBar.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}