O'Reilly logo

iOS 4 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required