UISplitViewController in Swift 5 iOS 13

Updated 25 June 2020

Save

Today, I will discuss the UISplitViewController and how we can use it in our app.

Swift version: 5
iOS version: 13
Xcode: 11

Let start about the UISplitViewController.

A split view controller is a master or container view controller that manages child view controllers in a hierarchical interface. An example of the split view controller is Mail.app. The split view controller has supported both the iPad and iPhone, since iOS 8.

To more details about this click here.

In this tutorial, we will show the country list in master view and selected country details will display in the child view controller

Getting Started

Step 1: Create a project from Xcode.

File ▸ New ▸ Project…. Choose the iOS ▸ Application ▸ Single View App template and create a new project.

Step 2: Drag a Split View Controller in the main storyboard.

 

You can see multiple elements in your storyboard when you add Split View Controller to the main storyboard:

Now run the app.

Steps 3: Create a MasterViewController for the UItableviewController where we parse the JSON file and bind the table view.

import countries.json file in the project directory. Click here countries to download the JSON file.

Before parsing the JSON file, we need to create a Country struct form containing the country data.

Now, create the getCountryList method for parse the JSON file and call the on viewDidLoad.

Now, showing the countries in the table view.

This will look like the below image.

 

Step 4: Create a details view controller page and add UILabel which will show the country name from the master view controller.

Final Step: Now will pass the date from the master controller to details view controller and render it on screen.

Now, Confirm the didSelectRowAt delegate in the master view controller and access the UILabel from the details view.

 

I hope the above blog will help you to learn about UISplitViewController and how we will use it in our app.

Thanks.

author
. . .

Leave a Comment

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


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home