Using Segue to Pass Data between View Controllers Swift

Hi our today’s topic is Using Segue to Pass Data between View Controllers – Objective C. As we are using Storyboard not the Xib’s which is user friendly for designing the UI of your app.

We already build our app using storyboard now we will pass data from one view controller to another using segue. When the app is launched, it displays a list on TableView. We will tap on any of them,it will bring you to another view, that supposes to display the details. We will display data on label on next view controller.

1. Assign ViewController Class :  and new view controller class name it DetailViewController. Now drag and drop a view controller on story board select it and change its class to DetailViewController.

Drop a label on it and make its outlet give it a name “displayLabel“.

We will be needing something that will be used to pass data from one controller and then display text on static Label.

2. Adding NavigationController : Select the first view controller and then from menu select Editor > Embed in > Navigation Controller.

Now create Segue from first view controller to second and name it to “toDetailController”.

3. Passing the Data from one controller to another : Segue manage transition from one controller to another controller. When a segue is triggered, before the visual transition occurs, the storyboard runtime calls “prepareForSegue:sender:” method of the current view controller. By using this method, we can pass needed data to the view controller that is about to be displayed.

We use unique identifiers for each segue. Identifier is a string that our application uses to distinguish one segue from another.

import “DetailViewController.swift”

Now we will write segue method in our ViewController.m file

Now build and run, and them click on any row and the detail view should display the selected item.

Today topic was :  Using Segue to Pass Data between View Controllers Swift next time we come up with something more exciting.

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.