Upload
oleksiy-kovyrin
View
215
Download
0
Embed Size (px)
Citation preview
8/14/2019 Standford CS 193P: 07-ViewControllers
1/37
CS193P - Lecture 7
iPhone Application Development
Designing iPhone ApplicationsView Controllers
8/14/2019 Standford CS 193P: 07-ViewControllers
2/37
Announcements
Grades for Assignment 1 are up on Coursework! A "means that you satisfied the requirements.
Assignment 3 due tomorrow (Wednesday, October 15)
iStanford commercial...
8/14/2019 Standford CS 193P: 07-ViewControllers
3/37
iStanford Commercial
8/14/2019 Standford CS 193P: 07-ViewControllers
4/37
Todays Topics
Questions on Assignment 3?
Designing iPhone Applications
View Controllers
Presence Intro
8/14/2019 Standford CS 193P: 07-ViewControllers
5/37
8/14/2019 Standford CS 193P: 07-ViewControllers
6/37
Two Flavors of Mail
8/14/2019 Standford CS 193P: 07-ViewControllers
7/37
Organizing Content
Focus on data
One thing at a time
Screenfuls of content
8/14/2019 Standford CS 193P: 07-ViewControllers
8/37
Patterns for Organizing Content
Navigation Bar Tab Bar
8/14/2019 Standford CS 193P: 07-ViewControllers
9/37
Navigation Bar
Hierarchy of content
Drill down into greater detail
8/14/2019 Standford CS 193P: 07-ViewControllers
10/37
Tab Bar
Self-contained modes
8/14/2019 Standford CS 193P: 07-ViewControllers
11/37
A Screenful of Content
Slice of your application
Views, data, logic
8/14/2019 Standford CS 193P: 07-ViewControllers
12/37
Parts of a Screenful
8/14/2019 Standford CS 193P: 07-ViewControllers
13/37
Parts of a Screenful
8/14/2019 Standford CS 193P: 07-ViewControllers
14/37
Parts of a Screenful
8/14/2019 Standford CS 193P: 07-ViewControllers
15/37
View Controllers
8/14/2019 Standford CS 193P: 07-ViewControllers
16/37
UIViewController
Basic building block
Manages a screenful of content
Subclass to add your application logic
View Controller
8/14/2019 Standford CS 193P: 07-ViewControllers
17/37
UIViewController
Basic building block
Manages a screenful of content
Subclass to add your application logic
8/14/2019 Standford CS 193P: 07-ViewControllers
18/37
UIViewController
Basic building block
Manages a screenful of content
Subclass to add your application logic
8/14/2019 Standford CS 193P: 07-ViewControllers
19/37
Your and Our View Controllers
Create your own UIViewController subclass for each screenful
Plug them together using existing composite view controllers
View Controller
View Controller
View Controller
NavigationController
8/14/2019 Standford CS 193P: 07-ViewControllers
20/37
Your and Our View Controllers
Create your own UIViewController subclass for each screenful
Plug them together using existing composite view controllers
View Controller
View Controller
View Controller
Tab BarController
8/14/2019 Standford CS 193P: 07-ViewControllers
21/37
Your View Controller Subclass
#import
@interface MyViewController : UIViewController {
// A view controller will usually
// manage views and data
NSMutableArray *myData;
UIView *myView;
}
// Expose some of its contents to clients
@property (readonly) NSArray *myData;
// And respond to actions
- (void)doSomeAction:(id)sender;
8/14/2019 Standford CS 193P: 07-ViewControllers
22/37
The View in View Controller
UIViewController superclass has a view property! @property (retain) UIView *view;
Loads lazily! As needed, on demand
! Can be purged on demand as well (low memory)
Sizing and positioning the view?! Depends on where its being used
! Dont make assumptions, be flexible
8/14/2019 Standford CS 193P: 07-ViewControllers
23/37
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];
[myView release];
self.view = myView; // The view controller now owns the view
8/14/2019 Standford CS 193P: 07-ViewControllers
24/37
Creating Your View with Interface Builder
Lay out a view in Interface Builder
View controller is files owner
Hook up view outlet
Create view controllerwith -initWithNibName:bundle:
8/14/2019 Standford CS 193P: 07-ViewControllers
25/37
Demo:
View Controllers with IB
8/14/2019 Standford CS 193P: 07-ViewControllers
26/37
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;
}
- (void)viewDidLoad
{ // Your view has been loaded
// Customize it here if needed
view.someWeirdProperty = YES;
}
8/14/2019 Standford CS 193P: 07-ViewControllers
27/37
View Controller Lifecycle- (void)viewWillAppear:(BOOL)animated
{[super viewWillAppear:animated];
// Your view is about to move onscreen
[self beginLoadingDataFromTheWeb];
[self startShowingLoadingProgress];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Your view is about to move offscreen
[self saveDataToDisk];
}
8/14/2019 Standford CS 193P: 07-ViewControllers
28/37
Loading & Saving Data
Lots of options out there, depends on what you need! NSUserDefaults
! Property lists
! SQLite
! Web services
! Something else?
8/14/2019 Standford CS 193P: 07-ViewControllers
29/37
Demo:
Loading & Saving Data
8/14/2019 Standford CS 193P: 07-ViewControllers
30/37
More View Controller Hooks
Automatically rotating user interface! - (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation;
Responding to low memory situations! - (void)didReceiveMemoryWarning;
8/14/2019 Standford CS 193P: 07-ViewControllers
31/37
Demo:
Rotating Your Interface
8/14/2019 Standford CS 193P: 07-ViewControllers
32/37
Autoresizing Your Views
view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleTopMargin;
8/14/2019 Standford CS 193P: 07-ViewControllers
33/37
Presence
8/14/2019 Standford CS 193P: 07-ViewControllers
34/37
Presence
Building an iPhone application for viewing online statusupdates, also known as presence! What are you doing right now?
Our assignments will be using Twitter! Could extend to Facebook updates, IM status, RSS feeds...
Four part assignment, each one builds on the previous
8/14/2019 Standford CS 193P: 07-ViewControllers
35/37
Presence - Part 1
Due next Wednesday 10/22
Goals! Create your own view controller subclasses
! Present a hierarchy using UINavigationController (next lecture)
8/14/2019 Standford CS 193P: 07-ViewControllers
36/37
Demo:
Presence
8/14/2019 Standford CS 193P: 07-ViewControllers
37/37
Questions?