IOS学习笔记---segue

来源:互联网 发布:java中interrupt用法 编辑:程序博客网 时间:2024/06/09 17:43

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 byadding 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.



原创粉丝点击