IOS: Unwind Segues

原文: 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值