IOS学习笔记---segue

Before asegue executes, the system gives the view controller involved a chance to prepare by calling prepareForSegue:. This is exactly the point at which you want to check to see whether the user tapped the Done button, and if so, create a new to-do item. You can check which one of the buttons got tapped, and if it was the Done button, create the item.


You have two view controllers configured in the storyboard, but there’s no connection between them. Transitions between scenes are called segues.


The push navigation is working just as it’s supposed to—but it’s not quite what you want when adding items. Push navigation is designed for a drill-down interface, where you’re providing more information about whatever the user selected. Adding an item, on the other hand, is amodal operation—the user performs some action that’s complete and self-contained, and then returns from that scene to the main navigation. The appropriate method of presentation for this type of scene is a modal segue.

To change the segue style

  1. In the outline view or on the canvas, select the segue from the table view controller to the add-to-do-item view controller.

  2. In the Attributes inspector, choose Modal from the pop-up menu next to the Style option.

Because a modal view controller doesn’t get added to the navigation stack, it doesn’t get a navigation bar from the table view controller’s navigation controller. However, you want to keep the navigation bar to provide the user with visual continuity. To give the add-to-do-item view controller a navigation bar when presented modally,embed it in its own navigation controller.

To add a navigation controller to the add-to-do-item view controller

  1. In the outline view, select View Controller.

  2. With the view controller selected, chooseEditor > Embed In > Navigation Controller.

As before, Xcode adds a navigation controller and shows the navigation bar at the top of the view controller. Next, configure this bar to add a title to this scene as well as two buttons,Cancel and Done

In addition to push and modal segues, Xcode provides an unwind segue. This segue allows users to go from a given scene back to a previous scene, and it provides a place for you to add your own code that gets executed when users navigate between those scenes. You can use an unwind segue to navigate back fromXYZAddToDoItemViewController to XYZToDoListViewController.

An unwind segue is created by adding an action method to the destination view controller (the view controller you want to unwind to). A method that can be unwound to must return an action (IBAction) and take in a storyboard segue (UIStoryboardSegue) as a parameter. Because you want to unwind back toXYZToDoListViewController, you need to add an action method with this format to theXYZToDoListViewController implementation.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值