2.1. Windows, Views, and View Controllers

Windows and views are the base classes for creating any type of user interface. A window represents a geometric space on a screen, while a view acts like a canvas for objects. Smaller UI components, such as buttons and text boxes, are all attached to a view, and that view is anchored to a window. Think of a window as the frame of a painting and the view as the actual canvas. A window is designed to host only view classes, but views can contain controls, images, and even host subviews such as tables and pickers. You'll learn about the different types of UI components in Chapters Chapter 3 and Chapter 10.

A view controller is a special kind of view object that manages how its views are displayed on the screen. View controllers can encapsulate one or more view objects and come with the plumbing to automatically handle screen rotations and transitions to other views when the user presses a button or flips the page. The view controller is designed as an intermediary between the view it is displaying and your underlying data and business logic.

Different types of controllers exist to provide different ways to display your data to the user. The iPod application employs a series of tabs along the bottom, allowing you to flip between artist and song lists, videos, and other information. The tab bar itself is available in one kind of view controller class (a tab bar controller), which is always visible on the screen regardless of which page the user is looking at. Other types of view controllers include table view controllers (which display your data in table form), image pickers (allowing the user to select an image from a library), and picker controllers (which solicit input using a series of scroll wheels).

A well-written application will consist of one window, at least one view controller, and at least one view encapsulated within the controller.