How is the UIViewController attached to the view controller?
All of these commands are automatically called at the appropriate times by iOS when it loads/shows/hides the view controller. It’s important to note that these methods are attached to the UIViewController and not to the UIView itself. You won’t get any of these features just by using a UIView.
Table of Contents
When does the view controller load the view?
Loads the view from the view controller if it hasn’t already been configured. The viewDidLoad event is only called when the view is created and loaded into memory, but the bounds of the view are not yet defined. This is a good place to initialize the objects that the view controller will use.
What is the purpose of the UIView class?
The UIView class is a rectangular area on the screen that is responsible for displaying content and handling user interactions with that content. It can also contain other views, allowing the developer to create complex interactive controls.
When is the viewdidload event called in iOS?
The viewDidLoad event is only called when the view is created and loaded into memory, but the bounds of the view are not yet defined. This is a good place to initialize the objects that the view controller will use. Called after the view has loaded. For view controllers created in code, this is after -loadView.
When is it called by default in the UIViewController lifecycle?
Called when the view is about to become visible. The default value does nothing. This is the first step in the life cycle where the limits are finalized. If you’re not using constraints or automatic layout, you probably want to update the subviews here. This is only available on iOS >=5.0.
What is the main class of UIViewController in iOS?
UIViewController is the parent class for all view controllers built to build an iOS app, including built-in ViewControllers like CollectionViewController and TableViewController. In iOS apps, we don’t need to instantiate the UIViewController class directly.
How are view controllers linked to the view hierarchy?
A view controller is closely tied to the views it manages and participates in handling events in its view hierarchy. Specifically, view controllers are UIResponder objects and are inserted into the response chain between the view controller’s root view and that view’s superview, which typically belongs to a different view controller.
What is the root of the UIView hierarchy?
The UIView hierarchy is a tree rooted at a window (UIWindow is a subclass of UIView). We can traverse this tree using subviews and superview properties. The UIViewController hierarchy starts from the rootViewController of a window.
How do you choose a view controller in UIKit?
When you present a view controller, UIKit looks for a view controller that provides a suitable context for the presentation. In many cases, UIKit chooses the closest container view controller, but it can also choose the root view controller of the window.