Segues

Most iOS applications have a number of view controllers that users navigate between. Storyboards allow you to set up these interactions as segues without having to write code.

A segue moves another view controller’s view onto the screen and is represented by an instance of UIStoryboardSegue. Each segue has a style, an action item, and an identifier. The style of a segue determines how the view controller will be presented. The action item is the view object in the storyboard file that triggers the segue, like a button, a table view cell, or some other UIControl. The identifier is used to programmatically access the segue. This is useful when you want to trigger a segue that does not come from an action item, like a shake or some other interface element that cannot be set up in the storyboard file.

Let’s start with a show segue. A show segue displays a view controller in whatever manner works best for the circumstance (usually by presenting it modally). The segue will be between the table view controller and the new view controller. The action items will be the table view’s cells; tapping a cell will show the view controller modally. (We will explain modal presentation in Chapter 14.)

In Main.storyboard, select the ItemCell prototype cell on the Items View Controller. Control-drag from the cell to the new view controller that you set up in the previous section. (Make sure you are Control-dragging from the cell and not the table view!) A black panel will appear that lists the possible styles for this segue. Select Show from the Selection Segue section (Figure 11.9).

Figure 11.9  Setting up a show segue

Setting up a show segue

Notice the arrow that goes from the table view controller to the new view controller. This is a segue. The icon in the circle tells you that this segue is a show segue – each segue has a unique icon.

Build and run the application. Tap a cell and the new view controller will slide up from the bottom of the screen. (Sliding up from the bottom is the default behavior when presenting a view controller modally.)

So far, so good! But there are two problems at the moment: The view controller is not displaying the information for the Item that was selected, and there is no way to dismiss the view controller to return to the ItemsViewController. You will fix the first issue in the next section, and you will fix the second issue in Chapter 12.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.218.215