How can we do a push xcode unwind segue programmatically?
I know the simple way is to use the storyboard and pull the button to the 'exit', but what I intend to do is to have some codes run first before the view is exited.
To go back to the rootViewController use:
[self.navigationController popToRootViewControllerAnimated:(BOOL)]
Or to go to a specific controller:
[self.navigationController popToViewController:
[[self.navigationController viewControllers]
objectAtIndex:THEINDEXOFTHEVIEWCONTROLLERTOUNWINDTO]
animated:YES];
For a little more detail, see my answer in this post: Push to root View controller in UIStoryboard
If you just want to execute some code before the exit (although keep it simple otherwise you'll get a UI lock until you return something), you could override canPerformUnwindSegueAction:fromViewController:withSender: on your destination controller.
Something like this perhaps:
- (BOOL)canPerformUnwindSegueAction:(SEL)action
fromViewController:(UIViewController *)fromViewController
withSender:(id)sender
{
// Some operation...
return YES; // Or NO if something went wrong and you want to abort
}
Otherwise, you could actually create the segue programmatically and manage animation/unwind logic by overriding segueForUnwindingToViewController:fromViewController:identifier:.
You can find the complete documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With