View Controller Programming Guide for iOS

suojae·2023년 12월 18일
0

UIKit

목록 보기
4/6

Overview


The Role of View Controllers

The UIViewController class defines the methods and properties for managing your views, handling events, transitioning from one view controller to another, and coordinating with other parts of your app.


View Management

The most important role of a view controller is to manage a hierarchy of views. Every view controller has a single root view that encloses all of the view controller’s content.

A container view controller manages its own views plus the root views from one or more of its child view controllers. The container does not manage the content of its children. It manages only the root view, sizing and placing it according to the container’s design.


Data Marshaling

A view controller acts as an intermediary between the views it manages and the data of your app.

You should always maintain a clean separation of responsibilities within your view controllers and data objects.


User Interactions

View controllers are responder objects and are capable of handling events that come down the responder chain.

view controllers rarely handle touch events directly. Instead, views usually handle their own touch events and report the results to a method of an associated delegate or target object, which is usually the view controller.


Resource Management

A view controller assumes all responsibility for its views and any objects that it creates.

When the available free memory is running low, UIKit asks apps to free up any resources that they no longer need. One way it does this is by calling the didReceiveMemoryWarning method of your view controllers. Use that method to remove references to objects that you no longer need or can recreate easily later.


Adaptivity

When the horizontal size class is compact, the view controller arranges its content vertically.


The View Controller Hierarchy


The Root View Controller

view controller is the anchor of the view controller hierarchy


Presenting a View Controller

There are two ways to display a view controller onscreen: embed it in a container view controller or present it.


The Presentation and Transition Process

profile
Hi 👋🏻 I'm an iOS Developer who loves to read🤓

0개의 댓글