DEV Community

AJITHKUMAR K
AJITHKUMAR K

Posted on • Originally published at dev.to

View and View Controller

View
In iOS, a view is a rectangular area that displays content and can be placed within the hierarchy of an app's user interface. It is an instance of the UIView class, which is a subclass of UIResponder.

It provides the infrastructure for displaying visual content on the screen and for handling user interactions. UIView has a number of properties that you can use to customise its appearance, such as its background colour, frame, and alpha value (which determines its transparency).
You can also add subviews to a view, which allows you to create complex layouts by nesting views within one another. For example, you might have a view that contains an image view and a label view, which are both subviews of the main view.

Views are typically created programmatically or in a storyboard using Interface Builder. They are then added to the view hierarchy of an app and positioned on the screen using layout constraints. Layout constraints are a set of rules that describe how a view should be positioned relative to its parent view or to other views in the layout.

View Controller

a view controller is a class that manages a view and its associated data. It is responsible for the presentation of the view on the screen and for handling user interactions with the view.
It is an instance of the UIViewController class, which is a subclass of UIResponder. It has a view property, which is an instance of UIView, and it is responsible for creating and configuring the view and for adding it to the view hierarchy.

A view controller can also manage the data displayed in its view, such as by fetching data from a network or a database and updating the view when the data changes. It can also respond to user interactions with the view, such as by handling button taps or gesture recognition.

Content ViewController

Content ViewControllers are the main type of View Controllers that we create. The Content View Controllers holds the content of the Application screen. In other words, we can say that the Content View Controller manages the discrete piece of the application content. The Content ViewController manages all the Views itself.

Container ViewController

Container ViewController is different from content ViewController in the sense that it acts as a parent View Controller, which collects information from the child view controllers. The task of the container view controller is to present the collected information to facilitate the navigation to the child view controllers. The container ViewController only manages the RootView, which incorporates one or more Child ViewControllers.

ViewManagement
ViewController manages the hierarchy of views. As shown in the below image, each ViewController contains a RootView which contains all the content of the view controller. All the custom views needed to maintain an iOS application is added to the root view to display the content.

Image description

Top comments (0)