Reputation: 1338
I'm creating a unwind segue using storyboard, following the instruction here.
But what I want to do is to create that unwind segue programmatically using swift,
The reason behind this is I want to create a default unwind segue to all of my UIViewController.
Upvotes: 0
Views: 176
Reputation: 534885
You can’t. A segue is something in the storyboard. Your code (programmatically) cannot see into the storyboard and change it.
Instead, you can do programmatically what the unwind segue did, such as pop back to a certain view controller.
But the general problem of "returning" to a certain view controller no matter what that may involve (some combination of dismiss and pop, etc.) is a very difficult and common one. It is certainly extremely annoying that, although a storyboard unwind
segue "knows" how to do that, there is no method that lets you do that in code. I can only suggest filing a bug report with Apple.
Upvotes: 1
Reputation: 16341
If you mean to go back to the root view controller you can use popToRootViewControllerAnimated
on navigationController
like this:
navigationController?.popToRootViewController(animated: true)
Or if you wish to pop back to a particular view controller then use:
navigationController?.popToViewController(secondViewController, animated: true)
Upvotes: 0