SlideShare a Scribd company logo
1 of 59
Download to read offline
CS193P - Lecture 4
            iPhone Application Development

            Building an Application
            Model, View, Controller
            Nib Files
            Controls and Target-Action




Friday, January 15, 2010                     1
Announcements
        • Friday sections
             ■   Friday, 4-5: 260-113


        • Invites to Developer Program will go out this weekend
             ■ Sign up and get your certificate when you get it
             ■ Start making apps that will run on Hardware!!




        • Waiting for a couple students to reply about P/NC spots
             ■   If we don’t hear back today, we’re giving them away




Friday, January 15, 2010                                               2
Today’s Topics
        • Application Lifecycle
        • Model, View, Controller design
        • Interface Builder and Nib Files
        • Controls and Target-Action
        • HelloPoly demo




Friday, January 15, 2010                    3
Review




Friday, January 15, 2010   4
Memory Management
        • Alloc/Init
             ■ -alloc assigns memory; -init sets up the object
             ■ Override -init, not -alloc




        • Retain/Release
             ■ Increment and decrement retainCount
             ■ When retainCount is 0, object is deallocated

             ■ Don’t call -dealloc!




        • Autorelease
             ■   Object is released when run loop completes



Friday, January 15, 2010                                         5
Setters, Getters, and Properties
        • Setters and Getters have a standard format:
               - (int)age;
               - (void)setAge:(int)age;


        • Properties allow access to setters and getters through dot
           syntax:
               @property age;


               int theAge = person.age;
               person.age = 21;




Friday, January 15, 2010                                               6
Building an Application




Friday, January 15, 2010          7
Anatomy of an Application
        • Compiled code
             ■ Your code
             ■ Frameworks




        • Nib files
             ■ UI elements and other objects
             ■ Details about object relationships




        • Resources (images, sounds, strings, etc)

        • Info.plist file (application configuration)


Friday, January 15, 2010                                8
App Lifecycle




              p p                   d                                   t
           ha                  lize                  ib               en                nt            pp
         nc                 ia                 i  nn               re
                                                                     v               ve       xit
                                                                                                  a
     Lau                 nit                 ma                  fo             dl ee        E
                       pi                 ad               ait                 n
                    Ap                  Lo                W                 Ha




Friday, January 15, 2010                                                                                   9
UIKit Framework
        • Provides standard interface elements
        • UIKit and you
             ■ Don’t fight the frameworks
             ■ Understand the designs and how you fit into them




Friday, January 15, 2010                                          10
UIKit Framework
        • Starts your application
        • Every application has a single instance of UIApplication
             ■   Singleton design pattern

                 @interface UIApplication
                 + (UIApplication *)sharedApplication
                 @end
             ■ Orchestrates the lifecycle of an application
             ■ Dispatches events

             ■ Manages status bar, application icon badge

             ■ Rarely subclassed

                  ■   Uses delegation instead




Friday, January 15, 2010                                             11
Delegation
        • Control passed to delegate objects to perform application-
          specific behavior
        • Avoids need to subclass complex objects
        • Many UIKit classes use delegates
             ■ UIApplication
             ■ UITableView

             ■ UITextField




Friday, January 15, 2010                                               12
UIApplicationDelegate
        • Xcode project templates have one set up by default
        • Object you provide that participates in application lifecycle
        • Can implement various methods which UIApplication will call
        • Examples:




Friday, January 15, 2010                                                  13
UIApplicationDelegate
        • Xcode project templates have one set up by default
        • Object you provide that participates in application lifecycle
        • Can implement various methods which UIApplication will call
        • Examples:
         - (void)applicationDidFinishLaunching:(UIApplication *)application;
         - (void)applicationWillTerminate:(UIApplication *)application;




Friday, January 15, 2010                                                       13
UIApplicationDelegate
        • Xcode project templates have one set up by default
        • Object you provide that participates in application lifecycle
        • Can implement various methods which UIApplication will call
        • Examples:
         - (void)applicationDidFinishLaunching:(UIApplication *)application;
         - (void)applicationWillTerminate:(UIApplication *)application;

         - (void)applicationWillResignActive:(UIApplication *)application;
         - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url;




Friday, January 15, 2010                                                                13
UIApplicationDelegate
        • Xcode project templates have one set up by default
        • Object you provide that participates in application lifecycle
        • Can implement various methods which UIApplication will call
        • Examples:
         - (void)applicationDidFinishLaunching:(UIApplication *)application;
         - (void)applicationWillTerminate:(UIApplication *)application;

         - (void)applicationWillResignActive:(UIApplication *)application;
         - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url;

         - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application;




Friday, January 15, 2010                                                                13
Info.plist file
        • Property List (often XML), describing your application
             ■ Icon appearance
             ■ Status bar style (default, black, hidden)

             ■ Orientation

             ■ Uses Wifi networking

             ■ System Requirements




        • Can edit most properties in Xcode
             ■ Project > Edit Active Target “Foo” menu item
             ■ On the properties tab




Friday, January 15, 2010                                           14
Model, View, Controller


        If you take nothing else away from this class...




Friday, January 15, 2010                                   15
Model, View, Controller


                               Controller



                       Model                View




Friday, January 15, 2010                           16
Model
        • Manages the app data and state

        • Not concerned with UI or presentation

        • Often persists somewhere

        • Same model should be reusable, unchanged in different
           interfaces




Friday, January 15, 2010                                          17
View
        • 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




Friday, January 15, 2010                                              18
Controller
        • 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.




Friday, January 15, 2010                                         19
Model, View, Controller


                               Controller



                       Model                View




Friday, January 15, 2010                           20
Model, View, Controller


                               Controller



                       Model                View




Friday, January 15, 2010                           20
Model, View, Controller


                               Controller



                       Model                View




Friday, January 15, 2010                           20
Model, View, Controller

                                 Controller
                           outlets

                           actions




           Model Object




Friday, January 15, 2010                      21
Model, View, Controller

                                 Controller
                           outlets

                           actions




           Model Object




Friday, January 15, 2010                      21
Model, View, Controller

                                 Controller
                           outlets

                           actions




           Model Object




Friday, January 15, 2010                      21
Interface Builder and Nibs




Friday, January 15, 2010             22
Nib files




Friday, January 15, 2010   23
Nib files




Friday, January 15, 2010   23
Nib Files - Design time
        • Helps you design the ‘V’ in MVC:

             ■   layout user interface elements

             ■   add controller objects

             ■   Connect the controller and UI




Friday, January 15, 2010                          24
Nib Loading
        • 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




Friday, January 15, 2010                                                  25
-awakeFromNib
        • Control point to implement any additional logic after nib
          loading
        • Default empty implementation on NSObject
        • You often implement it in your controller class
             ■   e.g. to restore previously saved application state
        • Guaranteed everything has been unarchived from nib, and all
           connections are made before -awakeFromNib is called
                           - (void)awakeFromNib {
                               // do customization here

                           }




Friday, January 15, 2010                                                26
Controls and Target-Action




Friday, January 15, 2010             27
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




Friday, January 15, 2010                                                        28
Controls - Target/Action
        • When event occurs, action is invoked on target object




                                                         Controller




Friday, January 15, 2010                                              29
Controls - Target/Action
        • When event occurs, action is invoked on target object
                               target:     myObject
                               action:     @selector(decrease)
                               event:      UIControlEventTouchUpInside




                                                          Controller




Friday, January 15, 2010                                                 29
Controls - Target/Action
        • When event occurs, action is invoked on target object
                               target:     myObject
                               action:     @selector(decrease)
                               event:      UIControlEventTouchUpInside




                                                          Controller




Friday, January 15, 2010                                                 29
Controls - Target/Action
        • When event occurs, action is invoked on target object
                               target:     myObject
                               action:     @selector(decrease)
                               event:      UIControlEventTouchUpInside




                                                          Controller




Friday, January 15, 2010                                                 29
Controls - Target/Action
        • When event occurs, action is invoked on target object
                               target:     myObject
                               action:     @selector(decrease)
                               event:      UIControlEventTouchUpInside
     UIControlEventTouchUpInside




                                                          Controller




Friday, January 15, 2010                                                 29
Controls - Target/Action
        • When event occurs, action is invoked on target object
                                      target:   myObject
                                      action:   @selector(decrease)
                                      event:    UIControlEventTouchUpInside
     UIControlEventTouchUpInside




                                                               Controller



                           -(void)decrease




Friday, January 15, 2010                                                      29
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




Friday, January 15, 2010                                                     30
Action Method Variations
         • Simple no-argument selector
                 - (void)increase {
                           // bump the number of sides of the polygon up
                           polygon.numberOfSides += 1;
                 }


         • Single argument selector - control is ‘sender’
                // for example, if control is a slider...
                - (void)adjustNumberOfSides:(id)sender {
                           polygon.numberOfSides = [sender value];
                }




Friday, January 15, 2010                                                   31
Action Method Variations
         • Two-arguments in selector (sender & event)

                    - (void)adjustNumberOfSides:(id)sender
                               withEvent:(UIEvent *)event
                    {
                           // could inspect event object if you needed to
                    }




Friday, January 15, 2010                                                    32
Multiple target-actions
        • Controls can trigger multiple actions on different targets in
           response to the same event

        • Different than Cocoa on the desktop where only one target-
           action is supported

        • Different events can be setup in IB




Friday, January 15, 2010                                                  33
Manual Target-Action
         • Same information IB would use
         • API and UIControlEvents found in UIControl.h
         • UIControlEvents is a bitmask
             @interface UIControl
             - (void)addTarget:(id)target action:(SEL)action
                     forControlEvents:(UIControlEvents)controlEvents;

             - (void)removeTarget:(id)target action:(SEL)action
                     forControlEvents:(UIControlEvents)controlEvents;
             @end




Friday, January 15, 2010                                                34
HelloPoly Demo




Friday, January 15, 2010   35
HelloPoly
        • This week’s assignment is a full MVC application
        • Next week’s assignment will flesh it out further
        • It is not designed to be a complex application
             ■   rather, provide a series of small studies of the fundamentals of a
                 Cocoa Touch application




Friday, January 15, 2010                                                              36
Model, View, Controller
        HelloPoly


                               Controller



                       Model                View




Friday, January 15, 2010                           37
Model, View, Controller
        HelloPoly


                                  Controller



                       Model                   View

                   PolygonShape




Friday, January 15, 2010                              37
Model, View, Controller
        HelloPoly


                                  Controller



                       Model                          View

                   PolygonShape                     UIKit controls
                                               PolygonView (next week)



Friday, January 15, 2010                                                 37
Model, View, Controller
        HelloPoly
                                   Controller


                                  Controller



                       Model                           View

                   PolygonShape                      UIKit controls
                                                PolygonView (next week)



Friday, January 15, 2010                                                  37
Model, View, Controller
        HelloPoly
                                Controller
                           numberOfSidesLabel
                           increaseButton
                           decreaseButton
                           polygonShape

                           increase
                           decrease




         PolygonShape




Friday, January 15, 2010                        38
Model, View, Controller
        HelloPoly
                                Controller
                           numberOfSidesLabel
                           increaseButton
                           decreaseButton
                           polygonShape

                           increase
                           decrease




         PolygonShape




Friday, January 15, 2010                        38
Model, View, Controller
        HelloPoly
                                Controller
                           numberOfSidesLabel
                           increaseButton
                           decreaseButton
                           polygonShape

                           increase
                           decrease




         PolygonShape




Friday, January 15, 2010                        38
Model, View, Controller
        HelloPoly
                                Controller
                           numberOfSidesLabel
                           increaseButton
                           decreaseButton
                           polygonShape

                           increase
                           decrease




         PolygonShape




Friday, January 15, 2010                        38
Nib Files - HelloPoly example
        • HelloPoly has all objects (model, view and controller) contained
           in the same MainWindow.xib file
             ■   More common to have UI broken up into several nib files


        • UIKit provides a variety of “View Controllers”
             ■   We will be introducing them with the Presence projects




Friday, January 15, 2010                                                     39
Questions?




Friday, January 15, 2010   40

More Related Content

Similar to 04 Model View Controller

Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...Bala Subra
 
iOS apps in Swift
iOS apps in SwiftiOS apps in Swift
iOS apps in SwiftNuno Dias
 
YUI App Framework
YUI App FrameworkYUI App Framework
YUI App FrameworkelHornair
 
Non functional requirements
Non functional requirementsNon functional requirements
Non functional requirementsPavel Růžička
 
Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)
Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)
Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)Google Developer Relations Team
 
Никита Корчагин - Introduction to Apple iOS Development.
Никита Корчагин - Introduction to Apple iOS Development.Никита Корчагин - Introduction to Apple iOS Development.
Никита Корчагин - Introduction to Apple iOS Development.DataArt
 
Enabling IoT Devices’ Hardware and Software Interoperability, IPSO Alliance (...
Enabling IoT Devices’ Hardware and Software Interoperability, IPSO Alliance (...Enabling IoT Devices’ Hardware and Software Interoperability, IPSO Alliance (...
Enabling IoT Devices’ Hardware and Software Interoperability, IPSO Alliance (...Open Mobile Alliance
 
Building a scalable app factory with Appcelerator Platform
Building a scalable app factory with Appcelerator PlatformBuilding a scalable app factory with Appcelerator Platform
Building a scalable app factory with Appcelerator PlatformAngus Fox
 
Building Applications Using the U2 Toolkit for .NET
Building Applications Using the U2 Toolkit for .NETBuilding Applications Using the U2 Toolkit for .NET
Building Applications Using the U2 Toolkit for .NETRocket Software
 
Resume_2016Aug
Resume_2016AugResume_2016Aug
Resume_2016AugI-Fan Chu
 
App Development with Swift, by Apple
App Development with Swift, by AppleApp Development with Swift, by Apple
App Development with Swift, by AppleFranco Cedillo
 
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1Violeta Salas
 
Android Jump Start
Android Jump StartAndroid Jump Start
Android Jump StartConFoo
 
Introduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for AndroidIntroduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for AndroidChris Hardy
 
Image Processing and Computer Vision in iPhone and iPad
Image Processing and Computer Vision in iPhone and iPadImage Processing and Computer Vision in iPhone and iPad
Image Processing and Computer Vision in iPhone and iPadOge Marques
 
2_Big Data Sources part3-Day 1-B Tools.pptx
2_Big Data Sources part3-Day 1-B Tools.pptx2_Big Data Sources part3-Day 1-B Tools.pptx
2_Big Data Sources part3-Day 1-B Tools.pptxssuser87a462
 

Similar to 04 Model View Controller (20)

Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
 
iOS apps in Swift
iOS apps in SwiftiOS apps in Swift
iOS apps in Swift
 
YUI App Framework
YUI App FrameworkYUI App Framework
YUI App Framework
 
Mocast Postmortem
Mocast PostmortemMocast Postmortem
Mocast Postmortem
 
Android intro 2010
Android intro 2010Android intro 2010
Android intro 2010
 
Titanium @ Minnebar
Titanium @ MinnebarTitanium @ Minnebar
Titanium @ Minnebar
 
Non functional requirements
Non functional requirementsNon functional requirements
Non functional requirements
 
Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)
Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)
Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)
 
Никита Корчагин - Introduction to Apple iOS Development.
Никита Корчагин - Introduction to Apple iOS Development.Никита Корчагин - Introduction to Apple iOS Development.
Никита Корчагин - Introduction to Apple iOS Development.
 
Enabling IoT Devices’ Hardware and Software Interoperability, IPSO Alliance (...
Enabling IoT Devices’ Hardware and Software Interoperability, IPSO Alliance (...Enabling IoT Devices’ Hardware and Software Interoperability, IPSO Alliance (...
Enabling IoT Devices’ Hardware and Software Interoperability, IPSO Alliance (...
 
Building a scalable app factory with Appcelerator Platform
Building a scalable app factory with Appcelerator PlatformBuilding a scalable app factory with Appcelerator Platform
Building a scalable app factory with Appcelerator Platform
 
stageTEK5_2016_cisner_w
stageTEK5_2016_cisner_wstageTEK5_2016_cisner_w
stageTEK5_2016_cisner_w
 
Building Applications Using the U2 Toolkit for .NET
Building Applications Using the U2 Toolkit for .NETBuilding Applications Using the U2 Toolkit for .NET
Building Applications Using the U2 Toolkit for .NET
 
Resume_2016Aug
Resume_2016AugResume_2016Aug
Resume_2016Aug
 
App Development with Swift, by Apple
App Development with Swift, by AppleApp Development with Swift, by Apple
App Development with Swift, by Apple
 
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
 
Android Jump Start
Android Jump StartAndroid Jump Start
Android Jump Start
 
Introduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for AndroidIntroduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for Android
 
Image Processing and Computer Vision in iPhone and iPad
Image Processing and Computer Vision in iPhone and iPadImage Processing and Computer Vision in iPhone and iPad
Image Processing and Computer Vision in iPhone and iPad
 
2_Big Data Sources part3-Day 1-B Tools.pptx
2_Big Data Sources part3-Day 1-B Tools.pptx2_Big Data Sources part3-Day 1-B Tools.pptx
2_Big Data Sources part3-Day 1-B Tools.pptx
 

More from Mahmoud

مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟Mahmoud
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتكMahmoud
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغيرMahmoud
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمMahmoud
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائقMahmoud
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقريةMahmoud
 
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيهمهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيهMahmoud
 
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟Mahmoud
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغيرMahmoud
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائقMahmoud
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتكMahmoud
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمMahmoud
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقريةMahmoud
 
Accident Investigation
Accident InvestigationAccident Investigation
Accident InvestigationMahmoud
 
Investigation Skills
Investigation SkillsInvestigation Skills
Investigation SkillsMahmoud
 
Building Papers
Building PapersBuilding Papers
Building PapersMahmoud
 
Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Mahmoud
 
Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Mahmoud
 
A Basic Modern Russian Grammar
A Basic Modern Russian Grammar A Basic Modern Russian Grammar
A Basic Modern Russian Grammar Mahmoud
 

More from Mahmoud (20)

مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتك
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغير
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقرية
 
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيهمهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
 
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغير
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتك
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقرية
 
Accident Investigation
Accident InvestigationAccident Investigation
Accident Investigation
 
Investigation Skills
Investigation SkillsInvestigation Skills
Investigation Skills
 
Building Papers
Building PapersBuilding Papers
Building Papers
 
Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02
 
Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01
 
A Basic Modern Russian Grammar
A Basic Modern Russian Grammar A Basic Modern Russian Grammar
A Basic Modern Russian Grammar
 
Teams Ar
Teams ArTeams Ar
Teams Ar
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

04 Model View Controller

  • 1. CS193P - Lecture 4 iPhone Application Development Building an Application Model, View, Controller Nib Files Controls and Target-Action Friday, January 15, 2010 1
  • 2. Announcements • Friday sections ■ Friday, 4-5: 260-113 • Invites to Developer Program will go out this weekend ■ Sign up and get your certificate when you get it ■ Start making apps that will run on Hardware!! • Waiting for a couple students to reply about P/NC spots ■ If we don’t hear back today, we’re giving them away Friday, January 15, 2010 2
  • 3. Today’s Topics • Application Lifecycle • Model, View, Controller design • Interface Builder and Nib Files • Controls and Target-Action • HelloPoly demo Friday, January 15, 2010 3
  • 5. Memory Management • Alloc/Init ■ -alloc assigns memory; -init sets up the object ■ Override -init, not -alloc • Retain/Release ■ Increment and decrement retainCount ■ When retainCount is 0, object is deallocated ■ Don’t call -dealloc! • Autorelease ■ Object is released when run loop completes Friday, January 15, 2010 5
  • 6. Setters, Getters, and Properties • Setters and Getters have a standard format: - (int)age; - (void)setAge:(int)age; • Properties allow access to setters and getters through dot syntax: @property age; int theAge = person.age; person.age = 21; Friday, January 15, 2010 6
  • 7. Building an Application Friday, January 15, 2010 7
  • 8. Anatomy of an Application • Compiled code ■ Your code ■ Frameworks • Nib files ■ UI elements and other objects ■ Details about object relationships • Resources (images, sounds, strings, etc) • Info.plist file (application configuration) Friday, January 15, 2010 8
  • 9. App Lifecycle p p d t ha lize ib en nt pp nc ia i nn re v ve xit a Lau nit ma fo dl ee E pi ad ait n Ap Lo W Ha Friday, January 15, 2010 9
  • 10. UIKit Framework • Provides standard interface elements • UIKit and you ■ Don’t fight the frameworks ■ Understand the designs and how you fit into them Friday, January 15, 2010 10
  • 11. UIKit Framework • Starts your application • Every application has a single instance of UIApplication ■ Singleton design pattern @interface UIApplication + (UIApplication *)sharedApplication @end ■ Orchestrates the lifecycle of an application ■ Dispatches events ■ Manages status bar, application icon badge ■ Rarely subclassed ■ Uses delegation instead Friday, January 15, 2010 11
  • 12. Delegation • Control passed to delegate objects to perform application- specific behavior • Avoids need to subclass complex objects • Many UIKit classes use delegates ■ UIApplication ■ UITableView ■ UITextField Friday, January 15, 2010 12
  • 13. UIApplicationDelegate • Xcode project templates have one set up by default • Object you provide that participates in application lifecycle • Can implement various methods which UIApplication will call • Examples: Friday, January 15, 2010 13
  • 14. UIApplicationDelegate • Xcode project templates have one set up by default • Object you provide that participates in application lifecycle • Can implement various methods which UIApplication will call • Examples: - (void)applicationDidFinishLaunching:(UIApplication *)application; - (void)applicationWillTerminate:(UIApplication *)application; Friday, January 15, 2010 13
  • 15. UIApplicationDelegate • Xcode project templates have one set up by default • Object you provide that participates in application lifecycle • Can implement various methods which UIApplication will call • Examples: - (void)applicationDidFinishLaunching:(UIApplication *)application; - (void)applicationWillTerminate:(UIApplication *)application; - (void)applicationWillResignActive:(UIApplication *)application; - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url; Friday, January 15, 2010 13
  • 16. UIApplicationDelegate • Xcode project templates have one set up by default • Object you provide that participates in application lifecycle • Can implement various methods which UIApplication will call • Examples: - (void)applicationDidFinishLaunching:(UIApplication *)application; - (void)applicationWillTerminate:(UIApplication *)application; - (void)applicationWillResignActive:(UIApplication *)application; - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url; - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application; Friday, January 15, 2010 13
  • 17. Info.plist file • Property List (often XML), describing your application ■ Icon appearance ■ Status bar style (default, black, hidden) ■ Orientation ■ Uses Wifi networking ■ System Requirements • Can edit most properties in Xcode ■ Project > Edit Active Target “Foo” menu item ■ On the properties tab Friday, January 15, 2010 14
  • 18. Model, View, Controller If you take nothing else away from this class... Friday, January 15, 2010 15
  • 19. Model, View, Controller Controller Model View Friday, January 15, 2010 16
  • 20. Model • Manages the app data and state • Not concerned with UI or presentation • Often persists somewhere • Same model should be reusable, unchanged in different interfaces Friday, January 15, 2010 17
  • 21. View • 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 Friday, January 15, 2010 18
  • 22. Controller • 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. Friday, January 15, 2010 19
  • 23. Model, View, Controller Controller Model View Friday, January 15, 2010 20
  • 24. Model, View, Controller Controller Model View Friday, January 15, 2010 20
  • 25. Model, View, Controller Controller Model View Friday, January 15, 2010 20
  • 26. Model, View, Controller Controller outlets actions Model Object Friday, January 15, 2010 21
  • 27. Model, View, Controller Controller outlets actions Model Object Friday, January 15, 2010 21
  • 28. Model, View, Controller Controller outlets actions Model Object Friday, January 15, 2010 21
  • 29. Interface Builder and Nibs Friday, January 15, 2010 22
  • 32. Nib Files - Design time • Helps you design the ‘V’ in MVC: ■ layout user interface elements ■ add controller objects ■ Connect the controller and UI Friday, January 15, 2010 24
  • 33. Nib Loading • 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 Friday, January 15, 2010 25
  • 34. -awakeFromNib • Control point to implement any additional logic after nib loading • Default empty implementation on NSObject • You often implement it in your controller class ■ e.g. to restore previously saved application state • Guaranteed everything has been unarchived from nib, and all connections are made before -awakeFromNib is called - (void)awakeFromNib { // do customization here } Friday, January 15, 2010 26
  • 35. Controls and Target-Action Friday, January 15, 2010 27
  • 36. 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 Friday, January 15, 2010 28
  • 37. Controls - Target/Action • When event occurs, action is invoked on target object Controller Friday, January 15, 2010 29
  • 38. Controls - Target/Action • When event occurs, action is invoked on target object target: myObject action: @selector(decrease) event: UIControlEventTouchUpInside Controller Friday, January 15, 2010 29
  • 39. Controls - Target/Action • When event occurs, action is invoked on target object target: myObject action: @selector(decrease) event: UIControlEventTouchUpInside Controller Friday, January 15, 2010 29
  • 40. Controls - Target/Action • When event occurs, action is invoked on target object target: myObject action: @selector(decrease) event: UIControlEventTouchUpInside Controller Friday, January 15, 2010 29
  • 41. Controls - Target/Action • When event occurs, action is invoked on target object target: myObject action: @selector(decrease) event: UIControlEventTouchUpInside UIControlEventTouchUpInside Controller Friday, January 15, 2010 29
  • 42. Controls - Target/Action • When event occurs, action is invoked on target object target: myObject action: @selector(decrease) event: UIControlEventTouchUpInside UIControlEventTouchUpInside Controller -(void)decrease Friday, January 15, 2010 29
  • 43. 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 Friday, January 15, 2010 30
  • 44. Action Method Variations • Simple no-argument selector - (void)increase { // bump the number of sides of the polygon up polygon.numberOfSides += 1; } • Single argument selector - control is ‘sender’ // for example, if control is a slider... - (void)adjustNumberOfSides:(id)sender { polygon.numberOfSides = [sender value]; } Friday, January 15, 2010 31
  • 45. Action Method Variations • Two-arguments in selector (sender & event) - (void)adjustNumberOfSides:(id)sender withEvent:(UIEvent *)event { // could inspect event object if you needed to } Friday, January 15, 2010 32
  • 46. Multiple target-actions • Controls can trigger multiple actions on different targets in response to the same event • Different than Cocoa on the desktop where only one target- action is supported • Different events can be setup in IB Friday, January 15, 2010 33
  • 47. Manual Target-Action • Same information IB would use • API and UIControlEvents found in UIControl.h • UIControlEvents is a bitmask @interface UIControl - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; - (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; @end Friday, January 15, 2010 34
  • 49. HelloPoly • This week’s assignment is a full MVC application • Next week’s assignment will flesh it out further • It is not designed to be a complex application ■ rather, provide a series of small studies of the fundamentals of a Cocoa Touch application Friday, January 15, 2010 36
  • 50. Model, View, Controller HelloPoly Controller Model View Friday, January 15, 2010 37
  • 51. Model, View, Controller HelloPoly Controller Model View PolygonShape Friday, January 15, 2010 37
  • 52. Model, View, Controller HelloPoly Controller Model View PolygonShape UIKit controls PolygonView (next week) Friday, January 15, 2010 37
  • 53. Model, View, Controller HelloPoly Controller Controller Model View PolygonShape UIKit controls PolygonView (next week) Friday, January 15, 2010 37
  • 54. Model, View, Controller HelloPoly Controller numberOfSidesLabel increaseButton decreaseButton polygonShape increase decrease PolygonShape Friday, January 15, 2010 38
  • 55. Model, View, Controller HelloPoly Controller numberOfSidesLabel increaseButton decreaseButton polygonShape increase decrease PolygonShape Friday, January 15, 2010 38
  • 56. Model, View, Controller HelloPoly Controller numberOfSidesLabel increaseButton decreaseButton polygonShape increase decrease PolygonShape Friday, January 15, 2010 38
  • 57. Model, View, Controller HelloPoly Controller numberOfSidesLabel increaseButton decreaseButton polygonShape increase decrease PolygonShape Friday, January 15, 2010 38
  • 58. Nib Files - HelloPoly example • HelloPoly has all objects (model, view and controller) contained in the same MainWindow.xib file ■ More common to have UI broken up into several nib files • UIKit provides a variety of “View Controllers” ■ We will be introducing them with the Presence projects Friday, January 15, 2010 39