Reputation: 117
I have two navigation Controllers for my views. I need to perform some operations when the user presses the back button to go to the previous view. Normally I would do this using the prepareForSague() function and using the sague Identifier.
What's the identifier (or how do I get it) of the back button that comes with navigation controller so i can use it in my prepareForSague function. Or is it done in other ways?
Upvotes: 1
Views: 604
Reputation: 1491
Please follow the steps:
popToViewController
: method.Or
Upvotes: 2
Reputation: 2690
One way of doing this would be to use the ViewWillDisappear()
function to detect when the navigation back button is pressed. Found the answer here.
Upvotes: 0
Reputation: 43
you have to use "viewWillDissapear" method for this, if you wanna use default back button.
But you may have to be careful here coz you only need this to work when really going back by back button, so every other actin - which calls "viewWillDissapear" method, you may need to make a flag to know its not the back action.
Upvotes: 0
Reputation: 5414
Just place your code inside viewWillDissapear
override func viewWillDisappear(animated: Bool)
That is, don't try to change the behavior of the back button, just write whatever code you need to be executed inside viewWillDissapear
Upvotes: 0
Reputation: 4904
your class can implement the UINavigationControllerDelegate
protocol and implement this method:
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
Upvotes: -1