View Controllers

Manage your interface using view controllers and facilitate navigation around your app's content.

Overview

You use view controllers to manage your UIKit app’s interface. A view controller manages a single root view, which may itself contain any number of subviews. User interactions with that view hierarchy are handled by your view controller, which coordinates with other objects of your app as needed. Every app has at least one view controller whose content fills the main window. If your app has more content than can fit onscreen at once, use multiple view controllers to manage different parts of that content.

A container view controller embeds the content of other view controllers into its own root view. A container view controller may mix custom views with the contents of its child view controllers to facilitate navigation or to create unique interfaces. For example, a UINavigationController object manages a navigation bar and a stack of child view controllers (only one of which is visible at a time), and provides an API to add and remove child view controllers from the stack.

UIKit provides several standard view controllers for navigation and managing specific types of content. You define the view controllers containing your app’s custom content. You may also define custom container view controllers to implement new navigation schemes.

Topics

Custom View Controllers

Subclass a view controller to manage your app's custom interface.

class UIViewController

An object that manages a view hierarchy for your UIKit app.

class UITableViewController

A view controller that specializes in managing a table view.

class UICollectionViewController

A view controller that specializes in managing a collection view.

protocol UIContentContainer

Methods for adapting the contents of your view controllers to size and trait changes.

Split View Interface

class UISplitViewController

A container view controller that implements a master-detail interface.

Navigation Interface

class UINavigationController

A container view controller that defines a stack-based scheme for navigating hierarchical content.

class UINavigationBar

Navigational controls displayed in a bar along the top of the screen, usually in conjunction with a navigation controller.

class UINavigationItem

The items to be displayed by a navigation bar when the associated view controller is visible.

Page View Interface

class UIPageViewController

A container view controller that manages navigation between pages of content, where each page is managed by a child view controller.

Tab View Interface

class UITabBarController

A container view controller that manages a radio-style selection interface, where the selection determines which child view controller to display.

class UITabBar

A control that displays one or more buttons in a tab bar for selecting between different subtasks, views, or modes in an app.

class UITabBarItem

An item in a tab bar.

Search Interface

class UISearchContainerViewController

A view controller that manages the presentation of search results in your interface.

class UISearchController

A view controller that manages the display of search results based on interactions with a search bar.

class UISearchBar

A specialized view for receiving search-related information from the user.

protocol UISearchResultsUpdating

A set of methods that let you update search results based on information the user enters into the search bar.

Images and Video

class UIImagePickerController

A view controller that manages the system interfaces for taking pictures, recording movies, and choosing items from the user's media library.

class UIVideoEditorController

A view controller that manages the system interface for trimming video frames and encoding a previously recorded movie.

Document Browser

Adding a Document Browser to Your App

Give users access to their local or remote documents from within your app.

class UIDocumentBrowserViewController

A view controller for browsing and performing actions on documents stored locally and in the cloud.

class UIDocumentPickerViewController

A view controller that provides access to documents or destinations outside your app’s sandbox.

Document Previewing

class UIDocumentInteractionController

A view controller that previews, opens, or prints files whose file format cannot be handled directly by your app.

iCloud Sharing

class UICloudSharingController

A view controller that presents standard screens for adding and removing people from a CloudKit share record.

Activities Interface

class UIActivityViewController

A view controller that you use to offer standard services from your app.

class UIActivityItemProvider

A proxy for data passed to an activity view controller.

protocol UIActivityItemSource

A set of methods used by an activity view controller to retrieve the data items to act on.

class UIActivity

An abstract class that you subclass to implement app-specific services.

Word Lookup

class UIReferenceLibraryViewController

A view controller that displays a standard interface for looking up the definition of a word or term.

Printer Picker

class UIPrinterPickerController

A view controller that displays the standard interface for selecting a printer.

Presentation Controllers

class UIPresentationController

An object that manages the transition animations and the presentation of view controllers onscreen.

Interface Restoration

Preserving Your App's UI Across Launches

Return your app to its previous state after it is terminated by the system.

protocol UIViewControllerRestoration

The methods that objects adopt so that they can act as a "restoration class” for view controllers during state restoration.

protocol UIObjectRestoration

The interface that restoration classes use to restore preserved objects.

protocol UIStateRestoring

Methods for adding objects to your state restoration archives.

Interface Orientation

func UIInterfaceOrientationIsPortrait(UIInterfaceOrientation)

Returns a Boolean value indicating whether the user interface is currently presented in a portrait orientation.

func UIInterfaceOrientationIsLandscape(UIInterfaceOrientation)

Returns a Boolean value indicating whether the user interface is currently presented in a landscape orientation.

See Also

User Interface

Views and Controls

Present your content onscreen and define the interactions allowed with that content.

View Layout

Use stack views to lay out the views of your interface automatically. Use Auto Layout when you require precise placement of your views.

Animation and Haptics

Provide feedback to users using view-based animations and haptics.

Windows and Screens

Provide a container for your view hierarchies and other content.