The Model-View-Controller (MVC) design pattern is a way of dividing your code in to independent functional areas. iPhone applications uses MVC design pattern. The model portion of MVC defines your application’s underlying data engine and is responsible for maintaining the integrity of that data. The view portion defines the user interface for your application and has no explicit knowledge of the origin of data displayed in that interface. The controller portion acts as a bridge between the model and view and facilitates updates between them.

UIKit Framework

UIKit framework provides standard interface elements. It starts your application. Every application has a single instance of UIApplication. Singleton design pattern

@interface UIApplication
+ (UIApplication *)sharedApplication

It orchestrates the lifecycle of an application, dispatches events, manages status bar, application icon badge.

Model View Controller (MVC)

Manages the app data and state. It has no concern with UI or presentation. Often persists somewhere. Same model should be reusable, unchanged in different interfaces.

Present the Model to the user in an appropriate interface. Allows user to manipulate data. Does not store any data (except to cache state). Easily reusable & configurable to display different data


Intermediary between Model & View. Updates the view when the model changes. Updates the model when the user manipulates the view. Typically where the app logic lives.

MVC Example

Interface Builder and Nibs

Nib Files – Design time helps you design the ‘V’ in MVC. It provides layout user interface elements, adds controller objects, connect the controller and UI.

At runtime, objects are unarchived values/settings in Interface Builder are restored. Ensures all outlets and actions are connected. Order of unarchiving is not defined. If loading the nib automatically creates objects and order is undefined, how do I customize? For example, to displaying initial state.

Controls and Target-Action

Controls – Events

View objects that allows users to initiate some type of action. Respond to variety of events:

  • Touch events
  • touchDown
  • touchDragged (entered, exited, drag inside, drag outside)
  • touchUp (inside, outside)
  • Value changed
  • Editing events
  • editing began
  • editing changed
  • editing ended
Controls – Target/Actions

Action Methods

3 different flavors of action method selector types

  • - (void)actionMethod;
  • - (void)actionMethod:(id)sender;
  • - (void)actionMethod:(id)sender withEvent:(UIEvent *)event;

UIEvent contains details about the event that took place.


Exercise – HelloPoly

These are simple instruction that you can follow to create a full MVC application. It is not designed to be a complex application rather, provide a series of small studies of the fundamentals of a Cocoa Touch application.

This application will have two buttons: increase and decrease. There will be a designer area of the application where the polygon will be drawn. Increase button will increase the number of vertices in the polygon where as Decrease button will decrease the number of vertices.

At this point, you might not be able to completely code this application. However, you should be comfortable making Model (PolygonShape Class) and Controller (Controller class) for this application. View part will be discussed in the next lecture.


Tagged with: ClassesiPhone

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.