`
dcj3sjt126com
  • 浏览: 1889304 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

IOS: Unwind Segues

    博客分类:
  • IOS
 
阅读更多

原文: http://www.intertech.com/Blog/iOS-Unwind-Segues/

In iOS 5, we were introduced to Storyboards and Segues.  While these features simplified the navigation process in our apps, we weren’t given a way to define a return to previous modal scenes via Interface Builder.

You may have noticed that in iOS 6, a green icon has been added to the control bar of each scene in the Storyboard.

exitIcon

This is a new, and surprisingly overlooked feature for iOS 6, which provides the missing “return” functionality.  It’s called an “unwind segue.”

The process is simple:

  • Add a private method inside each View Controller you wish to “unwind” to (a common mistake is to add this code into the View Controller you wish to unwind from).
  • This method includes one (and only one) parameter that’s a pointer to a UIStoryboardSegue, and a return type of IBAction .
  • The name of this method can be whatever you’d like.  However, all of the unwind segues will be listed in one place,so it’s a good idea to pick a descriptive naming pattern, such as unwindToRootVC.
  • There is no need to have anything in the body of this method.  The signature is what’s important.
   1: -(IBAction)unwindToRootVC:(UIStoryboardSegue *)segue
   2: {
   3:     // Nothing needed here.
   4: }
  • Inside your Storyboard, hold the control key down while dragging from your button (or other control) to the green exit icon below.

dragToExit

  • You will see a list of every unwind segue available here… that’s why coming up with a consistent and descriptive naming pattern is important.

selectUnwind

That’s it!  You are now able to return to any previous scene simply by selecting the appropriate unwind segue.  Also, unlike following a ‘regular’ segue, this will use not create a new object for every request!



Read more: http://www.intertech.com/Blog/ios-unwind-segues/#ixzz39OhH56Aj 
Follow us: @IntertechInc on Twitter | Intertech on Facebook

分享到:
评论

相关推荐

    Programming iOS 9(2015)

    Stay up-to-date on iOS 9 innovations, such as the new layout constraint notation, expanded UIKit dynamics, revised unwind segues, iPad multitasking, and the Contacts framework. All example code is ...

    Programming iOS 9 pdf 2015.12 完美无错版

    Stay up-to-date on iOS 9 innovations, such as the new layout constraint notation, expanded UIKit dynamics, revised unwind segues, iPad multitasking, and the Contacts framework. All example code is ...

    Beginning iOS 11 Programming with Swift by AppCoda

    13. 基本动画、视觉效果和Unwind Segues:本书通过创建简单的动画效果来增加应用的吸引力,并介绍Unwind Segues来处理复杂的视图控制器解构流程。 14. 静态表格视图、相机和NSLayoutConstraint:本书教授如何在不...

    ios原生入门之storyboard页面绘制源码(老安卓开发搞ios)

    Segue有两种主要类型:unwind segue(反向导航)和push segue(导航栈推送)。在Storyboard中,可以通过控制拖拽来创建segue,并设置其类型和属性。 接下来,我们需要了解Interface Builder(IB)中的关键概念,如...

    IOS应用源码——Navigation.zip

    7. ** unwind segues:** 在复杂的导航结构中,unwind segue是一种优雅的返回机制,它允许用户通过执行一个特定的action,从任意视图控制器回到其父控制器,甚至可以直接返回到根视图控制器。 8. **分割视图控制器...

    ios-StroyBoardDemo.zip

    在Storyboard中,你可以通过拖拽控件到Scene上,设置控件属性,以及通过 segues 连接不同Scene,定义它们之间的跳转逻辑。 1. **导航控制器(Navigation Controller)**:在Demo中,很可能是用到了Navigation ...

    Beginning iOS 11 Programming With Swift 4

    动画和视觉效果是提高用户体验的重要手段,本书讲解了如何在iOS应用中添加基础动画和视觉效果,以及如何使用Unwind Segues来退出视图控制器。同时,还介绍了Core Data数据库的基本使用,帮助开发者处理数据存储和...

    完整版 Beginning iOS-book swift4-.pdf

    第17章讲解了基本动画、视觉效果以及Unwind Segues的使用。 第18章探讨了静态表格视图、相机使用以及NSLayoutConstraint的高级布局技巧。 第19章介绍了Core Data的使用,它是iOS平台上广泛使用的本地数据存储解决...

    IOS应用源码之09 Nav.zip

    6. ** unwind segue**:如何使用unwind segue返回上一级视图控制器,这是一种优雅的返回方式。 7. **动态导航栏高度**:如果应用需要根据内容调整导航栏的高度,这里可能会有相应的实现。 8. **动画效果**:可能包含...

    iPhone开发【十二】多视图技术总结之四:Segmented Control

    在实际项目中,我们还可以结合Storyboard Segues或者 unwind segues 来简化视图间的导航逻辑。当用户点击Segmented Control时,触发 segue 直接跳转到相应的视图,这大大降低了代码的复杂性。 总之,Segmented ...

    swift-导航控制器的压缩使得可以将导航范围缩小到指定区域

    8. **使用 unwind segues**:在路径选择或文件选择等场景中,unwind segues 是一种优雅的返回方式,可以直接从任意视图控制器返回到起始点,而不需要通过一步步pop。 9. **处理barButtonItems**:在压缩导航时,...

    uinavigatongcontroller

    这时需要灵活运用`unwind segues`、`container views`等技术。 9. 历史记录管理:`UINavigationController`维护了用户导航的历史记录,这在实现“前进”和“后退”功能时非常有用。 10. 保存和恢复状态:当应用被...

    Natalie:Natalie-情节提要代码生成器(适用于Swift)

    1. **Segue识别**:Natalie能识别Storyboard中的所有segues,包括unwind segues,这些segues用于逆向导航回之前的视图控制器。 2. **代码生成**:根据识别到的segues,Natalie自动生成对应的Swift代码,这包括 ...

    SegueDemo 的代码

    点击Segues,可以为其设置标识符,这样在代码中可以通过这个标识符来定制Segue的行为,例如传递数据或者条件判断是否执行Segue。 在支持ARC(Automatic Reference Counting)的环境中,内存管理变得更加自动化,...

    StoryBoard应用示例

    UIStoryboardSegue是一个表示两个视图控制器之间转换的对象,有多种类型,如:push、modal、unwind等,每种类型对应不同的导航行为。例如,一个简单的push segue可以用于从一个表视图控制器导航到一个详情视图控制器...

    多种视图切换方式集锦.zipIOS应用例子源码下载

    7. **Storyboard Segues(故事板segue)**:在故事板中,通过拖拽segue来连接视图控制器,可以实现简单的视图切换,同时支持不同的Segue类型,如push、modal、unwind等。 源码集锦可能涵盖了以上部分或全部视图切换...

Global site tag (gtag.js) - Google Analytics