https://github.com/below/shortcutsegue
A sample to illustrate a storyboard segue navigation question
https://github.com/below/shortcutsegue
Last synced: about 1 year ago
JSON representation
A sample to illustrate a storyboard segue navigation question
- Host: GitHub
- URL: https://github.com/below/shortcutsegue
- Owner: below
- License: other
- Created: 2018-04-24T10:14:45.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-24T11:29:11.000Z (almost 8 years ago)
- Last Synced: 2025-01-26T02:44:07.964Z (about 1 year ago)
- Language: Swift
- Size: 3.08 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ShortcutSegue
A sample to illustrate a storyboard segue navigation question
## Objective
I would like to present the ViewController "C" directly from "A" while retaining the navigation flow, i.e. afterwards, the "Back" button on "C" should return to "B".
## Solution
It is actually quite simple: You just rearrange the stack of view controllers on the `UINavigationController`:
```Swift
let storyboard = self.storyboard! // As this is a sample, I am a bit liberal with force unwrapping
// This depends a bit from where you are coming. Sometimes you don't want the last viewController on the stack
var controllers : [UIViewController] = self.navigationController!.viewControllers
var controller = storyboard.instantiateViewController(withIdentifier: "B")
// Remember to do the things here you'd do in prepareForSegue!
controllers.append(controller)
controller = storyboard.instantiateViewController(withIdentifier: "C")
controllers.append(controller)
self.navigationController!.setViewControllers(controllers, animated: true)
```
Let me know what you think!