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 provides standard interface elements. It starts your application. Every application has a single instance of UIApplication. Singleton design pattern
@interface UIApplication + (UIApplication *)sharedApplication @end
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.
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
- touchDragged (entered, exited, drag inside, drag outside)
- touchUp (inside, outside)
- Value changed
- Editing events
- editing began
- editing changed
- editing ended
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.
- Using View Controller – iPhone Development
- UIKit Views and Animation – iPhone Development
- Tab Bar Controllers – iPhone Development
- Navigation Bar Controller – iPhone Development
- Views and Drawing – iPhone Development
- Currency Converter iPhone Application
- This Pointer, Static Members and destructors in C++
- More on Destructors and Static Data Members in C++
- Introduction to Classes and Objects in C++
- Object Oriented Programming Concepts in Java
- Exception Handling in C++
- MVC Programming in Struts – Slides and Source code
Popular Posts (last 30 days)
- Attendance Management Sys… 1185 view(s)
- Graph Implementation in C… 587 view(s)
- Implementing Stack Data S… 578 view(s)
- Circular Linked Lists 524 view(s)
- Applications of Stack in … 523 view(s)
- Simple Currency Converter… 442 view(s)
- GRASP Design Patterns 328 view(s)
- Advanced Data Structures … 265 view(s)
- C++ Tutorial for Intermed… 253 view(s)
- Sockets and Network Progr… 185 view(s)
TagsAndroid C-Sharp C/C++ language Classes Data structures Design Pattern Eclipse Game Development Graphics Design Books HTML iPhone JAVA JAVA GUI MIPS Assembly Mobile Programming Books Object Oriented PDF PHP Programming Programming Books Programming Languages Books Python RaphaelJS REST Source Code Threads Tutorial Web Development Books