What's the difference between View and ViewController?

Coming to Swift from Delphi, I thought that the view was the GUI of the application, and the storyboard was the visual representation of the code behind the view. ViewController was the only object that View interacted with. When a popular textbook says

In the old days, developers used to create a separate interface file for designing each view controller.

I think the "separate interface file" is the View file. But when I find out more, I get embarrassed. Below is a screenshot of an empty Main.storyboard from a new app, the text says

The official storyboard terminology for a view controller is "scene", but you can use the terms interchangeably. The scene is what the view controller represents in the storyboard ... Here you see the containing only empty view.

So I see a "single view controller" and not a view? The confusion is assembled when I note that any views (?) Displayed on the storyboard are called "View Controllers" in Swift.

So what's the difference between View and ViewController? How is the storyboard related? And what object "owns" something like a segue that exists outside of my (erroneous) understanding of these concepts?

+3


source to share


1 answer


Take a look at this post - What is the difference between a View controller and a View controller?

This is very good for me.

If you don't want to follow the link, here's a great description of the difference between view

and view controller

from Alex Wayne :



A view is an object that refers to the screen. It can also contain other views (sub-items) that are inside it and move with it. Views can receive touch events and change their visual state in response. The views are dumb and don't know about the structure of your application and just say to render themselves in some state.

The view controller cannot be directly displayed, it manages a group of view objects. View controllers usually have one view with many subzones. The view controller manages the state of these views. The view controller is smart and has knowledge of the inner workings of your application. It tells dumb viewers what to do and how to show themselves.

The view controller is the glue between your shared app and the screen. It manages the views it owns according to your application logic.

+4


source







All Articles