Basic Segues In Swift

Segues are a key factor to creating great apps with Swift and Xcode. They control the basic functionality of almost every app, passing off the current view of the app.

The Different Types of Segues

Show – Pushes the new destination view controller to the navigation stack. This is the most common of the ViewControllers.

Present Detail – This segue is used with UISplitViewController and is mostly meant for iPad applications.

Present Modally – Presents the ViewController modally and directly, with various animations that are set by the presentation option. On iPhone it covers the whole screen, but on iPad it commonly presents as a box in the center of the screen.

Present As Popover – This presents the destination ViewController as a popover on iPad, and tapping anywhere else on the screen will clear the screen. Although, on iPhone it presents the view over the whole screen.

Getting Started

First let’s create a new project. We will start with a single view app, but later we will add another view.

Give your project a name, any name will work. We won’t need any extensions, so leave those unchecked.

Adding The UI

Now navigate to the Main.storyboard file. This is where we will create the UI of our App.

Next, add a button by clicking on the Library button and searching for button. The Library tab is the button with a circle and square in the middle, up in the right hand corner.

Now, place the button in the center of the view controller.

Then we will create a new view controller by opening up the Library tab again and searching for view controller.

Change the color of the view controller to a different color than white, so we can see how to view animates and show that it changed. We do this by clicking on the Attributes Inspector and then choosing background and selecting a color.

Creating The Segue

Now we will create the Segue. To do this right click, or option click and drag to to the new ViewController. Then we will choose show, to present the destination view controller.

Testing it Out

Now build and run the app. You can press the start button in the top left hand corner or press Command+B. Any simulator will work with the app. Then click the button and the view should present over the whole screen.


Share on facebook
Share on twitter
Share on linkedin

Related Articles

Swiftly News Edition #1

Welcome   This is the very first edition of Swiftly News! A monthly newsletter that talks about everything Swift and how it affects an iOS developer.

Github V.S. Git

Many can confuse Git with Github, yet there are many key differences between the two. Understanding the differences and similarities between the two will help

Submitting To WWDC

The WWDC Scholarship Competition is an annual event held by Apple every year. You are required to create a playground and submit it in ten

Made with ❤ By Mason Dierkes

Close Menu