Chapter 2. Implementing Controllers and Views

2.0. Introduction

We write iOS applications using the MVC architecture. MVC is an abbreviation for Model-View-Controller. These are the three main components of an iOS application from an architectural perspective. The model is the brain of the application. It does the calculations; it creates a virtual world for itself that can live without the views and controllers. In other words, think of a model as a virtual copy of your application, without a face!

Controllers in Xcode usually refer to view controllers. Think of view controllers as a bridge between the model and your views. A view is the window through which your users interact with your application. It displays what’s inside the model most of the time, but in addition to that, it accepts users’ interactions. Any interaction between the user and your application is sent to a view, which then can be captured by a view controller and sent to the model.

In this chapter, you will learn how the structure of iOS applications is created and how to use views and view controllers to create intuitive applications.

2.1. Getting and Using the Application Delegate

Problem

An object needs to access your application’s delegate.

Solution

The UIApplication class has a method called delegate. You can retrieve the value of this property in order to get a reference to your application’s delegate:

Project1AppDelegate *delegate = (Project1AppDelegate *)[UIApplication
sharedApplication].delegate;

Note

Not all applications ...

Get iOS 4 Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.