> ## Content Index
> Fetch the complete content index at: https://yinguobing.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# Swift语言中的Segue与Unwind Segue
- URL: https://yinguobing.com/blog/segue-unwind-segue-in-swift/
- Published: 2015-08-11T21:39:58.000Z
- Updated: 2022-05-29T07:32:29.000Z
- Description: iOS中运行的应用拥有超过一个场景时，我们需要在不同场景之间进行切换，场景之间的切换过程即为Segue。
- Author: 尹国冰
- Tags: Swift

## Segue

iOS中运行的应用拥有超过一个场景时，我们需要在不同场景之间进行切换，例如在主界面点击注册按钮即切换到到注册场景。场景之间的切换过程即为Segue。伴随着Segue的往往还会有数据交换。通过StoryBoard中的鼠标拖拽可以快速的建立场景间切换所需的Segue。

![8_addbutton_drag_2x](https://yinguobing.com/blog/content/images/2015/08/8_addbutton_drag_2x-1024x502.png)

## Unwind Segue

在新的场景中完成对应任务后，需要切换回原来的场景，并将新场景中的数据传递回去，这个过程即为Unwind Segue。在StoryBoard中右击触发切换的按钮并拖拽到Scene Dock中的Exit按钮，即可选择对应的Unwind方法。当然在此之前需要在对应的view controller中重写 `prepareForSegue(_:)` 方法并对需要传递的数据做好准备，并实现具体的Unwind方法。