iOS8
UISplitViewController
master view controller
iOS development
mobile app development

Hiding the master view controller with UISplitViewController in iOS8

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Overview

UISplitViewController is an essential component for creating effective multi-column interfaces in iOS applications. First introduced in iOS 3.2, it has undergone several transformations, especially with the release of iOS 8, to better support various display environments and enhance user experience. This article provides an in-depth discussion on managing the master view controller in UISplitViewController , focusing on how to hide and manipulate it dynamically.

Introduction to UISplitViewController

UISplitViewController splits your application into two sections: a primary view (often termed as the master or the list) and a secondary view (often termed as the detail view). This is particularly useful for iPad applications where there's more real estate to take advantage of. In iOS 8, UISplitViewController gained capabilities to work on iPhone-sized screens as well.

iOS 8 and Enhancements

With iOS 8, UISplitViewController received significant API enhancements to support horizontal size classes and improve adaptability across devices and orientations. This brought about the ability to present split views on iPhones in landscape or on larger screens in portrait mode, thereby broadening the versatility of the component.

Hiding the Master View Controller

A common requirement is to hide the master view controller to provide more space for the detail view or to create a more unified single-view experience. Starting from iOS 8, the UISplitViewController API provides mechanisms to control when and how the master view controller is displayed.

Method for Hiding the Master View

The key property and methods to manage the display of the master view controller in a UISplitViewController include:

• **preferredDisplayMode: ** Allows you to specify how the split view controller should display its view controllers. The preferredDisplayMode can be set to values such as .automatic , .allVisible , .primaryHidden , and .oneBesideSecondary .

• **displayModeButtonItem: ** Provides a bar button item to toggle the master view visibility.

Example Configuration

Here is an example on how to set these properties to hide the master view controller:

• (void)viewDidLoad {

• (void)splitViewController:(UISplitViewController *)svc

• (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.