SlideShare a Scribd company logo
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

More Related Content

Similar to 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 Research
Nuxeo
 
7-22-2010-smpractices0710
7-22-2010-smpractices07107-22-2010-smpractices0710
7-22-2010-smpractices0710
Mathieu 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 Group
minddog
 
Hands on puremvc
Hands on puremvcHands on puremvc
Hands on puremvc
diomampo
 
QCON SP 2012
QCON SP 2012QCON SP 2012
QCON SP 2012
Cristiano Sanchez
 
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
Nuxeo
 
UX: What Not to Do
UX: What Not to DoUX: What Not to Do
UX: What Not to Do
Rob 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 company
Jazkarta, Inc.
 
International pbl conf_5b-c_kizaki
International pbl conf_5b-c_kizakiInternational pbl conf_5b-c_kizaki
International pbl conf_5b-c_kizaki
Satoru 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/2010
Wesley 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 XPages
Teamstudio
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
Alex Sharp
 
Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backbone
Daniel Lv
 
Driving Quality with TDD
Driving Quality with TDDDriving Quality with TDD
Driving Quality with TDD
Steven 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 2013
Max 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 project
Hristo 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 Display
Alexander Lobunets
 

Similar to 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
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
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
 

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 Investigation
Mahmoud
 
Investigation Skills
Investigation SkillsInvestigation Skills
Investigation Skills
Mahmoud
 
Building Papers
Building PapersBuilding Papers
Building Papers
Mahmoud
 
Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02
Mahmoud
 
Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01
Mahmoud
 
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

Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 

Recently uploaded (20)

Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 

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