Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a View and a View Controller? [closed]

from an iphone development perspective

like image 453
Mark Avatar asked Apr 13 '10 18:04

Mark


2 Answers

A view is an object that is drawn to the screen. It may also contain other views (subviews) that are inside it and move with it. Views can get touch events and tell listeners or delegates about any events that occur in them. Views are dumb, and do not know about the structure of your application, and are simply told to display themselves in some state, and listened to for events.

For example: a text label, a button, a checkbox, a progress bar.


A view controller is not drawable to the screen directly, it manages a group of view objects. View controllers usually have a single view with many subviews. The view controller manages the state of these views. A view controller is smart, and it knows how to interact with your application. It tells the dumb view objects what to do and how to show themselves.

For example: a screen that shows a list of users, an edit user form, a login screen.


A view controller is the glue between your overall application and the screen. It controls the views that it owns according to the logic of your application.

like image 147
Alex Wayne Avatar answered Sep 20 '22 19:09

Alex Wayne


The controller connects views (UI elements) to model objects. Views are for display, model objects are for data, controllers are the glue in between them.

See the Cocoa Fundamentals Guide for an explanation of the three tier architecture of the Model-View-Controller pattern.

like image 26
Nikolai Ruhe Avatar answered Sep 18 '22 19:09

Nikolai Ruhe