SlideShare ist ein Scribd-Unternehmen logo
1 von 88
Downloaden Sie, um offline zu lesen
CS193P - Lecture 6
        iPhone Application Development

        Designing iPhone Applications
        Model-View-Controller (Why and How?)
        View Controllers




Friday, January 22, 2010                       1
Announcements
        • Questions about Views?
        • Friday’s optional section...
             ■ Extended Office Hours
             ■ Gates 360, 3:30 - 5pm




Friday, January 22, 2010                 2
Today’s Topics
        • Designing iPhone Applications
        • Model-View-Controller (Why and How?)
        • View Controllers




Friday, January 22, 2010                         3
Designing iPhone Applications




Friday, January 22, 2010                4
Two Flavors of Mail




Friday, January 22, 2010                         5
Organizing Content




Friday, January 22, 2010     6
Organizing Content




Friday, January 22, 2010     6
Organizing Content




Friday, January 22, 2010     6
Organizing Content




Friday, January 22, 2010     6
Organizing Content
                           • Focus on your user’s data




Friday, January 22, 2010                                 6
Organizing Content
                           • Focus on your user’s data
                           • One thing at a time




Friday, January 22, 2010                                 6
Organizing Content
                           • Focus on your user’s data
                           • One thing at a time
                           • Screenfuls of content




Friday, January 22, 2010                                 6
Patterns for Organizing Content




Friday, January 22, 2010                              7
Patterns for Organizing Content
                           Navigation Bar




Friday, January 22, 2010                              7
Patterns for Organizing Content
                           Navigation Bar   Tab Bar




Friday, January 22, 2010                              7
Navigation Bar
                           • Hierarchy of content
                           • Drill down into greater detail




Friday, January 22, 2010                                      8
Navigation Bar
                           • Hierarchy of content
                           • Drill down into greater detail




Friday, January 22, 2010                                      8
Tab Bar
                           • Self-contained modes




Friday, January 22, 2010                            9
Tab Bar
                           • Self-contained modes




Friday, January 22, 2010                            9
A Screenful of Content
                             • Slice of your application
                             • Views, data, logic




Friday, January 22, 2010                                   10
Parts of a Screenful




                       Model                          View




Friday, January 22, 2010                                     11
Parts of a Screenful




                       Model                          View




                                     Controller




Friday, January 22, 2010                                     11
Parts of a Screenful




                       Model                          View




                                     Controller




Friday, January 22, 2010                                     12
Model-View-Controller
        (Why and How?)




Friday, January 22, 2010        13
Why Model-View-Controller?
        • Ever used the word “spaghetti” to describe code?
        • Clear responsibilities make things easier to maintain
        • Avoid having one monster class that does everything




Friday, January 22, 2010                                          14
Why Model-View-Controller?
        • Ever used the word “spaghetti” to describe code?
        • Clear responsibilities make things easier to maintain
        • Avoid having one monster class that does everything




Friday, January 22, 2010                                          14
Why Model-View-Controller?
        • Separating responsibilites also leads to reusability
        • By minimizing dependencies, you can take a model or view
          class you’ve already written and use it elsewhere
        • Think of ways to write less code




Friday, January 22, 2010                                             15
Communication and MVC
        • How should objects communicate?
        • Which objects know about one another?




Friday, January 22, 2010                          16
Communication and MVC
        • How should objects communicate?
        • Which objects know about one another?

        • Model
        • Example: Polygon class
        • Not aware of views or controllers
        • Typically the most reusable
        • Communicate generically using...        Model
             ■ Key-value observing
             ■ Notifications




Friday, January 22, 2010                                  17
Communication and MVC
        • How should objects communicate?
        • Which objects know about one another?

        • View
        • Example: PolygonView class
        • Not aware of controllers, may be
          aware of relevant model objects
        • Also tends to be reusable
                                                  View
        • Communicate with controller using...
             ■ Target-action
             ■ Delegation




Friday, January 22, 2010                                 18
Communication and MVC
        • How should objects communicate?
        • Which objects know about one another?

        • Controller
        • Knows about model and view objects
        • The brains of the operation
        • Manages relationships and data flow
        • Typically app-specific,                 Controller
           so rarely reusable




Friday, January 22, 2010                                       19
Communication and MVC




                       Model                   View




                                  Controller




Friday, January 22, 2010                              20
Communication and MVC




                       Model                   View




                                  Controller




Friday, January 22, 2010                              20
Communication and MVC




                       Model                               View


                          KVO,                     target-action,
                      notifications                  delegation



                                      Controller




Friday, January 22, 2010                                            20
View Controllers




Friday, January 22, 2010   21
Problem: Managing a Screenful
        • Controller manages views, data and application logic
        • Apps are made up of many of these
        • Would be nice to have a well-defined starting point
             ■ A la UIView for views
             ■ Common language for talking about controllers




Friday, January 22, 2010                                         22
Problem: Building Typical Apps
        • Some application flows are very common
             ■ Navigation-based
             ■ Tab bar-based

             ■ Combine the two


        • Don’t reinvent the wheel
        • Plug individual screens together to build an app




Friday, January 22, 2010                                     23
UIViewController
        • Basic building block
        • Manages a screenful of content
        • Subclass to add your application logic




                  View Controller   Views      Data   Logic




Friday, January 22, 2010                                      24
UIViewController
        • Basic building block
        • Manages a screenful of content
        • Subclass to add your application logic




Friday, January 22, 2010                           24
UIViewController
        • Basic building block
        • Manages a screenful of content
        • Subclass to add your application logic




Friday, January 22, 2010                           24
“Your” and “Our” View Controllers
        • Create your own UIViewController subclass for each screenful
        • Plug them together using existing composite view controllers




Friday, January 22, 2010                                                 25
“Your” and “Our” View Controllers
        • Create your own UIViewController subclass for each screenful
        • Plug them together using existing composite view controllers



                                        View Controller
                           Navigation
                           Controller     View Controller
                                            View Controller




Friday, January 22, 2010                                                 25
“Your” and “Our” View Controllers
        • Create your own UIViewController subclass for each screenful
        • Plug them together using existing composite view controllers


                                          View Controller

                            Tab Bar
                                          View Controller
                           Controller

                                          View Controller




Friday, January 22, 2010                                                 25
Your View Controller Subclass




Friday, January 22, 2010                26
Your View Controller Subclass
           #import <UIKit/UIKit.h>

           @interface MyViewController : UIViewController {
             // A view controller will usually
             // manage views and data
             NSMutableArray *myData;
             UILabel *myLabel;
           }




Friday, January 22, 2010                                      26
Your View Controller Subclass
           #import <UIKit/UIKit.h>

           @interface MyViewController : UIViewController {
             // A view controller will usually
             // manage views and data
             NSMutableArray *myData;
             UILabel *myLabel;
           }

           // Expose some of its contents to clients
           @property (readonly) NSArray *myData;




Friday, January 22, 2010                                      26
Your View Controller Subclass
           #import <UIKit/UIKit.h>

           @interface MyViewController : UIViewController {
             // A view controller will usually
             // manage views and data
             NSMutableArray *myData;
             UILabel *myLabel;
           }

           // Expose some of its contents to clients
           @property (readonly) NSArray *myData;

           // And respond to actions
           - (void)doSomeAction:(id)sender;




Friday, January 22, 2010                                      26
The “View” in “View Controller”




Friday, January 22, 2010                  27
The “View” in “View Controller”
        • UIViewController superclass has a view property
             ■   @property (retain) UIView *view;




Friday, January 22, 2010                                    27
The “View” in “View Controller”
        • UIViewController superclass has a view property
             ■   @property (retain) UIView *view;

        • Loads lazily
             ■ On demand when requested
             ■ Can be purged on demand as well (low memory)




Friday, January 22, 2010                                      27
The “View” in “View Controller”
        • UIViewController superclass has a view property
             ■   @property (retain) UIView *view;

        • Loads lazily
             ■ On demand when requested
             ■ Can be purged on demand as well (low memory)


        • Sizing and positioning the view?
             ■ Depends on where it’s being used
             ■ Don’t make assumptions, be flexible




Friday, January 22, 2010                                      27
When to call -loadView?




Friday, January 22, 2010          28
When to call -loadView?
        • Don’t do it!




Friday, January 22, 2010          28
When to call -loadView?
        • Don’t do it!
        • Cocoa tends to embrace a lazy philosophy
             ■ Call -release instead of -dealloc
             ■ Call -setNeedsDisplay instead of -drawRect:




Friday, January 22, 2010                                     28
When to call -loadView?
        • Don’t do it!
        • Cocoa tends to embrace a lazy philosophy
             ■ Call -release instead of -dealloc
             ■ Call -setNeedsDisplay instead of -drawRect:


        • Allows work to be deferred or coalesced
             ■   Performance!




Friday, January 22, 2010                                     28
Creating Your View in Code




Friday, January 22, 2010             29
Creating Your View in Code
        • Override -loadView
               ■   Never call this directly




           // Subclass of UIViewController
           - (void)loadView
           {




           }




Friday, January 22, 2010                      29
Creating Your View in Code
        • Override -loadView
               ■   Never call this directly
        • Create your views



           // Subclass of UIViewController
           - (void)loadView
           {
             MyView *myView = [[MyView alloc] initWithFrame:frame];

                   [myView release];
           }




Friday, January 22, 2010                                              29
Creating Your View in Code
        • Override -loadView
             ■   Never call this directly
        • Create your views
        • Set the view property


           // Subclass of UIViewController
           - (void)loadView
           {
             MyView *myView = [[MyView alloc] initWithFrame:frame];
             self.view = myView; // The view controller now owns the view
             [myView release];
           }




Friday, January 22, 2010                                                    29
Creating Your View in Code
        • Override -loadView
             ■   Never call this directly
        • Create your views
        • Set the view property
        • Create view controller with -init

           // Subclass of UIViewController
           - (void)loadView
           {
             MyView *myView = [[MyView alloc] initWithFrame:frame];
             self.view = myView; // The view controller now owns the view
             [myView release];
           }




Friday, January 22, 2010                                                    29
Creating Your View with Interface Builder




Friday, January 22, 2010                            30
Creating Your View with Interface Builder
        • Lay out a view in Interface Builder




Friday, January 22, 2010                            30
Creating Your View with Interface Builder
        • Lay out a view in Interface Builder
        • File’s owner is view controller class




Friday, January 22, 2010                            30
Creating Your View with Interface Builder
        • Lay out a view in Interface Builder
        • File’s owner is view controller class
        • Hook up view outlet




Friday, January 22, 2010                            30
Creating Your View with Interface Builder
        • Lay out a view in Interface Builder
        • File’s owner is view controller class
        • Hook up view outlet
        • Create view controller
           with -initWithNibName:bundle:




Friday, January 22, 2010                            30
Demo:
        View Controllers with IB




Friday, January 22, 2010           31
View Controller Lifecycle




Friday, January 22, 2010            32
View Controller Lifecycle
            - (id)initWithNibName:(NSString *)nibName
            bundle:(NSBundle *)bundle
            {
              if (self == [super init...]) {
                 // Perform initial setup, nothing view-related
                 myData = [[NSMutableArray alloc] init];
                 self.title = @“Foo”;
              }
              return self;
            }




Friday, January 22, 2010                                          32
View Controller Lifecycle




Friday, January 22, 2010            33
View Controller Lifecycle
            - (void)viewDidLoad
            {
              // Your view has been loaded
              // Customize it here if needed
              view.someWeirdProperty = YES;
            }




Friday, January 22, 2010                       33
View Controller Lifecycle




Friday, January 22, 2010            34
View Controller Lifecycle
            - (void)viewWillAppear:(BOOL)animated
            {
              [super viewWillAppear:animated];

                // Your view is about to show on the screen
                [self beginLoadingDataFromTheWeb];
                [self startShowingLoadingProgress];
            }




Friday, January 22, 2010                                      34
View Controller Lifecycle




Friday, January 22, 2010            35
View Controller Lifecycle
            - (void)viewWillDisappear:(BOOL)animated
            {
              [super viewWillDisappear:animated];

                // Your view is about to leave the screen
                [self rememberScrollPosition];
                [self saveDataToDisk];
            }




Friday, January 22, 2010                                    35
Loading & Saving Data
        • Lots of options out there, depends on what you need
             ■ NSUserDefaults
             ■ Property lists

             ■ CoreData

             ■ SQLite

             ■ Web services


        • Covering in greater depth in Lecture 9 on 4/29




Friday, January 22, 2010                                        36
Demo:
        Loading & Saving Data




Friday, January 22, 2010        37
More View Controller Hooks
        • Automatically rotating your user interface
        • Low memory warnings




Friday, January 22, 2010                               38
Supporting Interface Rotation




Friday, January 22, 2010                39
Supporting Interface Rotation
            - (BOOL)shouldAutorotateToInterfaceOrientation:
                    (UIInterfaceOrientation)interfaceOrientation
            {
              // This view controller only supports portrait
              return (interfaceOrientation ==
              	        UIInterfaceOrientationPortrait);
            }




Friday, January 22, 2010                                           39
Supporting Interface Rotation




Friday, January 22, 2010                40
Supporting Interface Rotation
            - (BOOL)shouldAutorotateToInterfaceOrientation:
                    (UIInterfaceOrientation)interfaceOrientation
            {
              // This view controller supports all orientations
              // except for upside-down.
              return (interfaceOrientation !=
              	        UIInterfaceOrientationPortraitUpsideDown);
            }




Friday, January 22, 2010                                            40
Demo:
        Rotating Your Interface




Friday, January 22, 2010          41
Autoresizing Your Views




Friday, January 22, 2010          42
Autoresizing Your Views
        view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
                                UIViewAutoresizingFlexibleHeight;




Friday, January 22, 2010                                            42
Autoresizing Your Views
        view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
                                UIViewAutoresizingFlexibleHeight;




Friday, January 22, 2010                                            42
Autoresizing Your Views
        view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
                                UIViewAutoresizingFlexibleHeight;

        view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
                                UIViewAutoresizingFlexibleTopMargin;




Friday, January 22, 2010                                               42
Autoresizing Your Views
        view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
                                UIViewAutoresizingFlexibleHeight;

        view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
                                UIViewAutoresizingFlexibleTopMargin;




Friday, January 22, 2010                                               42
Questions?




Friday, January 22, 2010   43

Weitere ähnliche Inhalte

Ähnlich wie 06 View Controllers

Nuxeo World Session: Semantic Technologies - Update on Recent Research
Nuxeo World Session: Semantic Technologies - Update on Recent ResearchNuxeo World Session: Semantic Technologies - Update on Recent Research
Nuxeo World Session: Semantic Technologies - Update on Recent ResearchNuxeo
 
7-22-2010-smpractices0710
7-22-2010-smpractices07107-22-2010-smpractices0710
7-22-2010-smpractices0710Mathieu Plourde
 
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP GroupDeveloping Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Groupminddog
 
Hands on puremvc
Hands on puremvcHands on puremvc
Hands on puremvcdiomampo
 
Nuxeo World Session: Mobile ECM Apps with Nuxeo EP
Nuxeo World Session: Mobile ECM Apps with Nuxeo EPNuxeo World Session: Mobile ECM Apps with Nuxeo EP
Nuxeo World Session: Mobile ECM Apps with Nuxeo EPNuxeo
 
UX: What Not to Do
UX: What Not to DoUX: What Not to Do
UX: What Not to DoRob Surrency
 
Building a successful open source consulting company
Building a successful open source consulting companyBuilding a successful open source consulting company
Building a successful open source consulting companyJazkarta, Inc.
 
International pbl conf_5b-c_kizaki
International pbl conf_5b-c_kizakiInternational pbl conf_5b-c_kizaki
International pbl conf_5b-c_kizakiSatoru Kizaki
 
Incorporating site level knowledge to extract structured data from web forums...
Incorporating site level knowledge to extract structured data from web forums...Incorporating site level knowledge to extract structured data from web forums...
Incorporating site level knowledge to extract structured data from web forums...George Ang
 
GateIn - Presented at Atlanta JUG on 1/19/2010
GateIn - Presented at Atlanta JUG on 1/19/2010GateIn - Presented at Atlanta JUG on 1/19/2010
GateIn - Presented at Atlanta JUG on 1/19/2010Wesley Hales
 
Agile business analysis the changing role of business analysts in agile sof...
Agile business analysis   the changing role of business analysts in agile sof...Agile business analysis   the changing role of business analysts in agile sof...
Agile business analysis the changing role of business analysts in agile sof...Nari Kannan
 
jQuery Comes to XPages
jQuery Comes to XPagesjQuery Comes to XPages
jQuery Comes to XPagesTeamstudio
 
Blogging and social media EI
Blogging and social media EIBlogging and social media EI
Blogging and social media EISocial Bits
 
Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backboneDaniel Lv
 
Driving Quality with TDD
Driving Quality with TDDDriving Quality with TDD
Driving Quality with TDDSteven Mak
 
Art vs science[讲述分析和设计流程的ppt]
Art vs science[讲述分析和设计流程的ppt]Art vs science[讲述分析和设计流程的ppt]
Art vs science[讲述分析和设计流程的ppt]keen2211
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Max Klymyshyn
 
Choosing the right JavaScript library/framework/toolkit for our project
Choosing the right JavaScript library/framework/toolkit for our projectChoosing the right JavaScript library/framework/toolkit for our project
Choosing the right JavaScript library/framework/toolkit for our projectHristo Chakarov
 
Mobile Device as a Smart Metering Display
Mobile Device as a Smart Metering DisplayMobile Device as a Smart Metering Display
Mobile Device as a Smart Metering DisplayAlexander Lobunets
 

Ähnlich wie 06 View Controllers (20)

Nuxeo World Session: Semantic Technologies - Update on Recent Research
Nuxeo World Session: Semantic Technologies - Update on Recent ResearchNuxeo World Session: Semantic Technologies - Update on Recent Research
Nuxeo World Session: Semantic Technologies - Update on Recent Research
 
7-22-2010-smpractices0710
7-22-2010-smpractices07107-22-2010-smpractices0710
7-22-2010-smpractices0710
 
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP GroupDeveloping Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
 
Hands on puremvc
Hands on puremvcHands on puremvc
Hands on puremvc
 
QCON SP 2012
QCON SP 2012QCON SP 2012
QCON SP 2012
 
Nuxeo World Session: Mobile ECM Apps with Nuxeo EP
Nuxeo World Session: Mobile ECM Apps with Nuxeo EPNuxeo World Session: Mobile ECM Apps with Nuxeo EP
Nuxeo World Session: Mobile ECM Apps with Nuxeo EP
 
UX: What Not to Do
UX: What Not to DoUX: What Not to Do
UX: What Not to Do
 
Building a successful open source consulting company
Building a successful open source consulting companyBuilding a successful open source consulting company
Building a successful open source consulting company
 
International pbl conf_5b-c_kizaki
International pbl conf_5b-c_kizakiInternational pbl conf_5b-c_kizaki
International pbl conf_5b-c_kizaki
 
Incorporating site level knowledge to extract structured data from web forums...
Incorporating site level knowledge to extract structured data from web forums...Incorporating site level knowledge to extract structured data from web forums...
Incorporating site level knowledge to extract structured data from web forums...
 
GateIn - Presented at Atlanta JUG on 1/19/2010
GateIn - Presented at Atlanta JUG on 1/19/2010GateIn - Presented at Atlanta JUG on 1/19/2010
GateIn - Presented at Atlanta JUG on 1/19/2010
 
Agile business analysis the changing role of business analysts in agile sof...
Agile business analysis   the changing role of business analysts in agile sof...Agile business analysis   the changing role of business analysts in agile sof...
Agile business analysis the changing role of business analysts in agile sof...
 
jQuery Comes to XPages
jQuery Comes to XPagesjQuery Comes to XPages
jQuery Comes to XPages
 
Blogging and social media EI
Blogging and social media EIBlogging and social media EI
Blogging and social media EI
 
Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backbone
 
Driving Quality with TDD
Driving Quality with TDDDriving Quality with TDD
Driving Quality with TDD
 
Art vs science[讲述分析和设计流程的ppt]
Art vs science[讲述分析和设计流程的ppt]Art vs science[讲述分析和设计流程的ppt]
Art vs science[讲述分析和设计流程的ppt]
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013
 
Choosing the right JavaScript library/framework/toolkit for our project
Choosing the right JavaScript library/framework/toolkit for our projectChoosing the right JavaScript library/framework/toolkit for our project
Choosing the right JavaScript library/framework/toolkit for our project
 
Mobile Device as a Smart Metering Display
Mobile Device as a Smart Metering DisplayMobile Device as a Smart Metering Display
Mobile Device as a Smart Metering Display
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"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
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Kürzlich hochgeladen (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"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...
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

06 View Controllers

  • 1. CS193P - Lecture 6 iPhone Application Development Designing iPhone Applications Model-View-Controller (Why and How?) View Controllers Friday, January 22, 2010 1
  • 2. Announcements • Questions about Views? • Friday’s optional section... ■ Extended Office Hours ■ Gates 360, 3:30 - 5pm Friday, January 22, 2010 2
  • 3. Today’s Topics • Designing iPhone Applications • Model-View-Controller (Why and How?) • View Controllers Friday, January 22, 2010 3
  • 5. Two Flavors of Mail Friday, January 22, 2010 5
  • 10. Organizing Content • Focus on your user’s data Friday, January 22, 2010 6
  • 11. Organizing Content • Focus on your user’s data • One thing at a time Friday, January 22, 2010 6
  • 12. Organizing Content • Focus on your user’s data • One thing at a time • Screenfuls of content Friday, January 22, 2010 6
  • 13. Patterns for Organizing Content Friday, January 22, 2010 7
  • 14. Patterns for Organizing Content Navigation Bar Friday, January 22, 2010 7
  • 15. Patterns for Organizing Content Navigation Bar Tab Bar Friday, January 22, 2010 7
  • 16. Navigation Bar • Hierarchy of content • Drill down into greater detail Friday, January 22, 2010 8
  • 17. Navigation Bar • Hierarchy of content • Drill down into greater detail Friday, January 22, 2010 8
  • 18. Tab Bar • Self-contained modes Friday, January 22, 2010 9
  • 19. Tab Bar • Self-contained modes Friday, January 22, 2010 9
  • 20. A Screenful of Content • Slice of your application • Views, data, logic Friday, January 22, 2010 10
  • 21. Parts of a Screenful Model View Friday, January 22, 2010 11
  • 22. Parts of a Screenful Model View Controller Friday, January 22, 2010 11
  • 23. Parts of a Screenful Model View Controller Friday, January 22, 2010 12
  • 24. Model-View-Controller (Why and How?) Friday, January 22, 2010 13
  • 25. Why Model-View-Controller? • Ever used the word “spaghetti” to describe code? • Clear responsibilities make things easier to maintain • Avoid having one monster class that does everything Friday, January 22, 2010 14
  • 26. Why Model-View-Controller? • Ever used the word “spaghetti” to describe code? • Clear responsibilities make things easier to maintain • Avoid having one monster class that does everything Friday, January 22, 2010 14
  • 27. Why Model-View-Controller? • Separating responsibilites also leads to reusability • By minimizing dependencies, you can take a model or view class you’ve already written and use it elsewhere • Think of ways to write less code Friday, January 22, 2010 15
  • 28. Communication and MVC • How should objects communicate? • Which objects know about one another? Friday, January 22, 2010 16
  • 29. Communication and MVC • How should objects communicate? • Which objects know about one another? • Model • Example: Polygon class • Not aware of views or controllers • Typically the most reusable • Communicate generically using... Model ■ Key-value observing ■ Notifications Friday, January 22, 2010 17
  • 30. Communication and MVC • How should objects communicate? • Which objects know about one another? • View • Example: PolygonView class • Not aware of controllers, may be aware of relevant model objects • Also tends to be reusable View • Communicate with controller using... ■ Target-action ■ Delegation Friday, January 22, 2010 18
  • 31. Communication and MVC • How should objects communicate? • Which objects know about one another? • Controller • Knows about model and view objects • The brains of the operation • Manages relationships and data flow • Typically app-specific, Controller so rarely reusable Friday, January 22, 2010 19
  • 32. Communication and MVC Model View Controller Friday, January 22, 2010 20
  • 33. Communication and MVC Model View Controller Friday, January 22, 2010 20
  • 34. Communication and MVC Model View KVO, target-action, notifications delegation Controller Friday, January 22, 2010 20
  • 36. Problem: Managing a Screenful • Controller manages views, data and application logic • Apps are made up of many of these • Would be nice to have a well-defined starting point ■ A la UIView for views ■ Common language for talking about controllers Friday, January 22, 2010 22
  • 37. Problem: Building Typical Apps • Some application flows are very common ■ Navigation-based ■ Tab bar-based ■ Combine the two • Don’t reinvent the wheel • Plug individual screens together to build an app Friday, January 22, 2010 23
  • 38. UIViewController • Basic building block • Manages a screenful of content • Subclass to add your application logic View Controller Views Data Logic Friday, January 22, 2010 24
  • 39. UIViewController • Basic building block • Manages a screenful of content • Subclass to add your application logic Friday, January 22, 2010 24
  • 40. UIViewController • Basic building block • Manages a screenful of content • Subclass to add your application logic Friday, January 22, 2010 24
  • 41. “Your” and “Our” View Controllers • Create your own UIViewController subclass for each screenful • Plug them together using existing composite view controllers Friday, January 22, 2010 25
  • 42. “Your” and “Our” View Controllers • Create your own UIViewController subclass for each screenful • Plug them together using existing composite view controllers View Controller Navigation Controller View Controller View Controller Friday, January 22, 2010 25
  • 43. “Your” and “Our” View Controllers • Create your own UIViewController subclass for each screenful • Plug them together using existing composite view controllers View Controller Tab Bar View Controller Controller View Controller Friday, January 22, 2010 25
  • 44. Your View Controller Subclass Friday, January 22, 2010 26
  • 45. Your View Controller Subclass #import <UIKit/UIKit.h> @interface MyViewController : UIViewController { // A view controller will usually // manage views and data NSMutableArray *myData; UILabel *myLabel; } Friday, January 22, 2010 26
  • 46. Your View Controller Subclass #import <UIKit/UIKit.h> @interface MyViewController : UIViewController { // A view controller will usually // manage views and data NSMutableArray *myData; UILabel *myLabel; } // Expose some of its contents to clients @property (readonly) NSArray *myData; Friday, January 22, 2010 26
  • 47. Your View Controller Subclass #import <UIKit/UIKit.h> @interface MyViewController : UIViewController { // A view controller will usually // manage views and data NSMutableArray *myData; UILabel *myLabel; } // Expose some of its contents to clients @property (readonly) NSArray *myData; // And respond to actions - (void)doSomeAction:(id)sender; Friday, January 22, 2010 26
  • 48. The “View” in “View Controller” Friday, January 22, 2010 27
  • 49. The “View” in “View Controller” • UIViewController superclass has a view property ■ @property (retain) UIView *view; Friday, January 22, 2010 27
  • 50. The “View” in “View Controller” • UIViewController superclass has a view property ■ @property (retain) UIView *view; • Loads lazily ■ On demand when requested ■ Can be purged on demand as well (low memory) Friday, January 22, 2010 27
  • 51. The “View” in “View Controller” • UIViewController superclass has a view property ■ @property (retain) UIView *view; • Loads lazily ■ On demand when requested ■ Can be purged on demand as well (low memory) • Sizing and positioning the view? ■ Depends on where it’s being used ■ Don’t make assumptions, be flexible Friday, January 22, 2010 27
  • 52. When to call -loadView? Friday, January 22, 2010 28
  • 53. When to call -loadView? • Don’t do it! Friday, January 22, 2010 28
  • 54. When to call -loadView? • Don’t do it! • Cocoa tends to embrace a lazy philosophy ■ Call -release instead of -dealloc ■ Call -setNeedsDisplay instead of -drawRect: Friday, January 22, 2010 28
  • 55. When to call -loadView? • Don’t do it! • Cocoa tends to embrace a lazy philosophy ■ Call -release instead of -dealloc ■ Call -setNeedsDisplay instead of -drawRect: • Allows work to be deferred or coalesced ■ Performance! Friday, January 22, 2010 28
  • 56. Creating Your View in Code Friday, January 22, 2010 29
  • 57. Creating Your View in Code • Override -loadView ■ Never call this directly // Subclass of UIViewController - (void)loadView { } Friday, January 22, 2010 29
  • 58. Creating Your View in Code • Override -loadView ■ Never call this directly • Create your views // Subclass of UIViewController - (void)loadView { MyView *myView = [[MyView alloc] initWithFrame:frame]; [myView release]; } Friday, January 22, 2010 29
  • 59. Creating Your View in Code • Override -loadView ■ Never call this directly • Create your views • Set the view property // Subclass of UIViewController - (void)loadView { MyView *myView = [[MyView alloc] initWithFrame:frame]; self.view = myView; // The view controller now owns the view [myView release]; } Friday, January 22, 2010 29
  • 60. Creating Your View in Code • Override -loadView ■ Never call this directly • Create your views • Set the view property • Create view controller with -init // Subclass of UIViewController - (void)loadView { MyView *myView = [[MyView alloc] initWithFrame:frame]; self.view = myView; // The view controller now owns the view [myView release]; } Friday, January 22, 2010 29
  • 61. Creating Your View with Interface Builder Friday, January 22, 2010 30
  • 62. Creating Your View with Interface Builder • Lay out a view in Interface Builder Friday, January 22, 2010 30
  • 63. Creating Your View with Interface Builder • Lay out a view in Interface Builder • File’s owner is view controller class Friday, January 22, 2010 30
  • 64. Creating Your View with Interface Builder • Lay out a view in Interface Builder • File’s owner is view controller class • Hook up view outlet Friday, January 22, 2010 30
  • 65. Creating Your View with Interface Builder • Lay out a view in Interface Builder • File’s owner is view controller class • Hook up view outlet • Create view controller with -initWithNibName:bundle: Friday, January 22, 2010 30
  • 66. Demo: View Controllers with IB Friday, January 22, 2010 31
  • 67. View Controller Lifecycle Friday, January 22, 2010 32
  • 68. View Controller Lifecycle - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle { if (self == [super init...]) { // Perform initial setup, nothing view-related myData = [[NSMutableArray alloc] init]; self.title = @“Foo”; } return self; } Friday, January 22, 2010 32
  • 69. View Controller Lifecycle Friday, January 22, 2010 33
  • 70. View Controller Lifecycle - (void)viewDidLoad { // Your view has been loaded // Customize it here if needed view.someWeirdProperty = YES; } Friday, January 22, 2010 33
  • 71. View Controller Lifecycle Friday, January 22, 2010 34
  • 72. View Controller Lifecycle - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // Your view is about to show on the screen [self beginLoadingDataFromTheWeb]; [self startShowingLoadingProgress]; } Friday, January 22, 2010 34
  • 73. View Controller Lifecycle Friday, January 22, 2010 35
  • 74. View Controller Lifecycle - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // Your view is about to leave the screen [self rememberScrollPosition]; [self saveDataToDisk]; } Friday, January 22, 2010 35
  • 75. Loading & Saving Data • Lots of options out there, depends on what you need ■ NSUserDefaults ■ Property lists ■ CoreData ■ SQLite ■ Web services • Covering in greater depth in Lecture 9 on 4/29 Friday, January 22, 2010 36
  • 76. Demo: Loading & Saving Data Friday, January 22, 2010 37
  • 77. More View Controller Hooks • Automatically rotating your user interface • Low memory warnings Friday, January 22, 2010 38
  • 79. Supporting Interface Rotation - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { // This view controller only supports portrait return (interfaceOrientation == UIInterfaceOrientationPortrait); } Friday, January 22, 2010 39
  • 81. Supporting Interface Rotation - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { // This view controller supports all orientations // except for upside-down. return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } Friday, January 22, 2010 40
  • 82. Demo: Rotating Your Interface Friday, January 22, 2010 41
  • 83. Autoresizing Your Views Friday, January 22, 2010 42
  • 84. Autoresizing Your Views view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; Friday, January 22, 2010 42
  • 85. Autoresizing Your Views view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; Friday, January 22, 2010 42
  • 86. Autoresizing Your Views view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; Friday, January 22, 2010 42
  • 87. Autoresizing Your Views view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; Friday, January 22, 2010 42