Views & View Controllers
The internal organization of an iOS application is built around view controllers. Every view that is present on a storyboard has a parent, which is the View Controller. There is a minimum of one ViewController per application. It makes switching between the different sections of the UI easier.
All ViewControllers descend from the UIViewController parent class. It outlines every property and technique for controlling our perceptions. Additionally, this class controls events and view controller transitions. Additionally, it serves as a coordinator for the various application components.
Types of ViewControllers
Two varieties of ViewControllers exist:
1.Content ViewController: The majority of the View Controllers we develop are Content ViewControllers. The application screen’s content is stored in the Content View Controllers. Put otherwise, the discrete portion of the application content is managed by the Content View Controller. Every view is independently managed by the Content ViewController.
2.Container ViewController: The way that the container view controller functions as a parent view controller gathering data from the child view controllers sets it apart from the content view controller. Presenting the gathered data to the child view controllers to make navigation easier is the responsibility of the container view controller. Only the RootView, which includes one or more Child ViewControllers, is managed by the container ViewController.
Both Content ViewController and Container ViewController are combined in the majority of iOS applications.
View Management
The ViewController controls the hierarchy of views in iOS development. Every ViewController has a RootView that houses all of the view controller’s content, as seen in the illustration below. To display the content, all the custom views required for maintaining an iOS application are added to the root view. The relationship between RootView, ViewController, and its subviews is depicted in the following image. A RootView serves as the Parent View of all the views included in the View Controllers, and each subview is referenced by a Super View that consists of a chain of views.
Data Marshaling
The data of our iOS application is shown on the screen by a View Controller in iOS development. It serves as a conduit between the application data and its developer-created Views. A class that derives from the UIViewController class is allocated to each ViewController in the Storyboard.
The class that we designate to the ViewController contains every property and method declared in the UIViewController. However, we must declare our properties and methods in the ViewController class in order to construct our application. It aids in the management of our application’s visual representation.