Transcript Lecture 5
COMP 446 / ELEC 446
Mobile Device Applications
Scott Cutler
Professor in the Practice of Computer Technology
Department of Computer Science
Department of Electrical and Computer Engineering
[email protected]
9/19/12
Wednesday 2-3:30, DH 1046
Agenda
Events of the Week
Next week’s assignment and class
Review of Assignment 2
Some more on Views, Gestures, Protocols
Questions on Assignment #3
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
2
Events of the Week
Apple announces iPhone 5: What you need to know
I miss Apple's reality distortion field
Apple's dock connector change is awful, don't kid yourselves
Apple's iPhone 5: 2 million preorders, 24 hours and a unique upgrade cycle
Apple fanboys fight back against Samsung
Fox: iPhone 5 has laser keyboard, holographic images
Yahoo Tells Workers: No More BlackBerrys
What you gain and lose with Office 2013 subscriptions
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
3
Current Roster
Victor Acuna
Ryan Artecona
Gbenga Badipe
Peter Chang
Joan Chao
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
4
Current Roster (2)
Alex Chiu
Heaven Chen
Lingo Dai
Weibo He
Sahil Hingorani
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
5
Current Roster (3)
Abdul Nimeri
Bill Robertson
Frank Salinas
Tyler Siegert
Austin Witt
Matthew Zhao
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
6
COMP 446 Syllabus
Lecture 1 - 8/22/12 - Introduction
Lecture 2 - 8/29/12- Assignment 1 issues and questions from videos
Watch before:
3, 4 (demo part)
Assignment:
#3 – Graphing Universal Calculator
Assignment due: Tuesday, 9/18 6:00 am (Monday 30:00)
Lecture 4 - 9/12/12 - Assignment 3 issues and questions from videos
Watch before:
1, 2
Assignment:
#2 – Function Calculator
Assignment due: Friday, 9/7 6:00 am (Thursday 30:00)
Lecture 3 - 9/05/12 - Assignment 2 issues and questions from videos
Watch before:
None
Assignment:
#1 - Calculator
Assignment due: Friday, 8/31 6:00 am (Thursday 30:00)
Watch before:
4 (post demo), 5, 6
Assignment:
Continue with #3 – Graphing Universal Calculator
Assignment due: Tuesday, 9/18 6:00 am (Monday 30:00)
Lecture 5 - 9/19/12 - Assignment 3 issues and questions from videos
Watch before:
Watch 7 before class, 8 after class
Assignment:
#4 – Fiickr Top Places
Assignment due: Friday, 9/28 6:00 am (Thursday 30:00)
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
7
COMP 446 Syllabus
Lecture 6 - 9/26/12 - Assignment 4 issues and questions from videos
Lecture 7 - 10/03/12 - Assignment 5 issues and questions from videos
Watch before:
Assignment:
10 (after Tab Bar), 11, 12
1: #6 – Fiickr Core Data
- Likely to be broken into required and optional parts
- Optional part required for A+
2: Final Project Topic (due before next class)
Assignment due: Friday, 10/12 6:00 am (Thursday 30:00)
Lecture 8 - 10/10/12 - Assignment 6 issues and SQL
Watch before:
8, 9 very beginning of 10
Assignment:
#5 – Fiickr Map Places
Assignment due: Friday, 10/5 6:00 am (Thursday 30:00)
Watch before:
13, 14
Assignment:
Final Project Proposal
Assignment due: Tuesday, 10/16 6:00 am (Monday 30:00)
Lecture 9 - 10/17/12 - iOS 6
Watch before:
Optional 15, 16
Assignment:
iOS 6 app
Assignment due: Friday, 10/26 6:00 am (Thursday 30:00)
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
8
COMP 446 Syllabus
Lecture 10 - 10/24/12 – HTML 5
Lecture 11 - 10/31/12 - TBD
Assignment:
Continue working on Final Project
Assignment due: Wednesday, 11/28 2:00pm
Lecture 14 - 11/21/12 – No class, but continue on final project
Assignment:
Continue working on Final Project
Assignment due: Wednesday, 11/28 2:00pm
Lecture 13 - 11/14/12 - Individual meetings on Final Project
Assignment:
Continue working on Final Project
Assignment due: Wednesday, 11/28 2:00pm
Lecture 12 - 11/7/12- Android vs. iOS vs. Windows Phone group debate
Watch before:
Optional 17, 18
Assignment:
Major Final Project Feature
Assignment due: Friday, 11/2 6:00 am (Thursday 30:00)
Assignment:
Continue working on Final Project
Assignment due: Wednesday, 11/28 2:00pm
Lecture 15 - 11/28/12 - Final Presentations
Assignment:
Document Final Project
Assignment due: By time assigned for COMP 446 final (there is NO final exam)
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
9
Final Projects
Projects will be individual
An acceptable iPad project can couple to an iPhone project
Projects can be in iOS, Windows 8 or Android
You are responsible for Win 8 or Android technology
I have a small number of iOS devices that can be used by students
without one.
May have to share
Likely have to deploy from a non-community Mac
Must utilize at least one major and one minor iOS framework and
feature not covered in first 6 assignments; preferably >1 major.
Project must be pre-approved
Often because proposed project too difficult to complete
Sometimes need to be modified for content
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
10
Final Project Ideas
Augmented Reality is always a winner
There are some interesting robots utilizing the
iPhone.
One could make a board game with iPhone players
and iPad game board.
OpenGL is a good feature.
External universal frameworks are NOT allowed.
Utilizing a backend is good, but not much credit given
for backend logic
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
11
Week 6
Watch CS193p lectures #8 (second part), #9 and #10 (through
Tab Bar)
Make progress on CS193p Assignment #4
Try and complete before 9/26 class. Due Friday, 9/28 6:00 am .
Submit assignments, review lectures at www.comp446.com
Start thinking about big project
Next week’s lecture – UIScrollView and Table View Controllers
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
12
What is coming up in the assignments?
Assignment #3 – Graphing Calculator
Core Graphics, views, frames, bounds, etc.
Navigation Controllers
Storyboards and Segues
Gesture recognizers
Protocols and Delegates
iPad apps, Universal Apps, SplitView controllers
Assignment #1 was easy. #2 was more difficult. #3
incorporates many new paradigms
Will need to watch through video 7 for iPad information
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
13
What is coming up in the assignments?
Assignment #4 – Flickr Top Places
Tab bar controllers
TableView controllers
ScrollViews
Data from the internet
Assignment #5 – Fast Flickr Map
Builds on Assignment #4
Multi Threading / Grand Central Dispatch
MapKit
Assignment #6 – Core Data Flickr
UIDocument
Core Data
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
14
Assignment #3a Comments
Most people handled graph title display wrong. What is the purpose of
the title?
Still had a number of @synthesize issues with “_”
Back button too often said BACK
For many x did not complete a number.
Many of you took away your undo key. It should still be there.
Some pans did not pan linearly. Graph should follow finger – and do
so in real time.
Axis should always be full screen
For calculator, if you don’t do rotation properly, don’t allow rotation.
Some submissions did not handle rotation of the graph.
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
15
Target / Action
When a controller wants a view to get back to it when
something happens, it use Target / Action.
The Target is the class instance to receive a
message from the view when something happens
The Action is the method sent to the Target when the
trigger happens.
View items, like buttons, can have multiple
target/action pairs.
A target and its associated method can be triggered
by multiple situations.
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
16
Protocols, Delegates and DataSources
Protocols define a set of required and optional methods and
properties to accomplish something
Protocols can be placed in an existing or a separate header file.
Use @class className to forward reference a class
Protocols can inherit other protocols – adding the inherited requirements
and optional methods to their own
Delegates are classes which publicize that they handle the
requirements of a protocol. These classes get set as the delegate
normally in a property of the class defining the protocol.
It is safe to send a required protocol method to a class that states it
handles a protocol. It must check respondsTo for optional methods.
<myProtocol> is used to identify that a class responds to myProtocol
Can also be added to an iVar or property.
DataSources are Delagates handling data values
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
17
Protocols and Assignment #3
The Calculator is an MVC with the
CalculatorBrain as the Model
The Graphing MVC is supposed to be generic
and use a protocol for its view’s data
(valueAtPointX)
Where should the protocol be defined?
Where should the protocol be implemented?
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
18
Assignment 3 Protocol Definition
GraphView controller uses delegate to get y
value for given x
GraphView wants to be generic
As such, GraphView is a great place to define
protocol
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
19
Assignment 3 DataSource
Can go in either GraphViewController or
CalculatorViewController.
If in GraphViewController, then
GraphViewController is no longer generic
Preferred location is in CalculatorViewController
Keeps GraphViewController generic
Perceived as being more difficult; but actually not
Requires indirect setting of DataSource
Removes need to pass equation
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
20
Assignment 3 DataSource Steps
CVC <GraphViewDataSource>
self.gvc.dataSource=self;
GVC
-(void)setDataSource:(id)dataSource
{self.gv.dataSource = dataSource; }
GV
@property (nonatomic, weak) id
<GraphViewDataSource> dataSource;
@synthesize dataSource=_dataSource;
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
21
Review of Video 7 Items
Many of the slides to follow come directly
from the Fall 2011 Stanford CS193p slide
deck.
Some come from earlier versions of CS193p
which I think were a bit clearer than the
current deck
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
22
UIToolbar
Collection of UIBarButtonItems
Enable by checking “Shows Toolbar”
Toolbar items belong to view, not controller
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
23
UISplitViewController
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
24
UISplitViewControllerDelegate
Required to see left side in portrait mode.
- (BOOL)splitViewController:(UISplitViewController *)sender
shouldHideViewController:(UIViewController *)master
inOrientation:(UIInterfaceOrientation)orientation
{return UIInterfaceOrientationIsPortrait(orientation); } // or YES/NO
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
25
Left Side Going Away, Show BBI
- (void)splitViewController:(UISplitViewController *)sender
willHideViewController:(UIViewController *)master
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)popover
{
barButtonItem.title = @“Master”; // use a better word than “Master”!
// setSplitViewBarButtonItem: must put the bar button
somewhere on screen
// probably in a UIToolbar or a UINavigationBar
[detailViewController setSplitViewBarButtonItem:barButtonItem];
}
Your job to write setSplitViewBarButtonItem
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
26
Left Side Coming Back, Remove BBI
- (void)splitViewController:(UISplitViewController *)sender
willShowViewController:(UIViewController *)master
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// removeSplitViewBarButtonItem: must remove the bar button from its toolbar
[detailViewController removeSplitViewBarButtonItem:nil];
}
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
27
Sample setSplitViewBarButtonItem
- (void)setSplitViewBarButtonItem:(UIBarButtonItem *)barButtonItem
{
UIToolbar *toolbar = [self toolbar]; // might be outlet or calculated
NSMutableArray *toolbarItems = [toolbar.items mutableCopy];
if (_splitViewBarButtonItem) [toolbarItems removeObject:_splitViewBarButtonItem];
// put the bar button on the left of our existing toolbar
if (barButtonItem) [toolbarItems insertObject:barButtonItem atIndex:0];
toolbar.items = toolbarItems;
_splitViewBarButtonItem = barButtonItem;
}
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
28
Updating Detail View Controller
Target/Action or Segue
Since detail always on screen and segue replaces
view, Target / Action more common
Get pointer to detail view controller:
id detailViewController = [[self.splitViewController viewControllers] lastObject];
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
29
UIPopoverController
Not a UIViewController subclass
Typically created in storyboard
contentViewController property for displayed
viewController
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
30
Universal Applications
If not enabled, runs iPhone apps a 2X
If target for iPad, but nothing special done, you
end up with a full screen application
Typical paradigm is with UISplitViewController
Create separate iPhone and iPad storyboards
Often significant reuse of most classes
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
31
Am I Running on a iPad???
BOOL iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
If (self.splitViewController) { … } //splitViewController only on iPad
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
32
View Controller Lifecycle
Made significantly simpler in iOS 5 with ARC
Main entry points
- awakeFromNib // earliest entry
- viewDidLoad // outlets set, bounds not set
- viewWillAppear:(BOOL)animated
SEC - 9/19/12
VERY close to appearing.
May happen multiple times
Put expensive operations in separate thread
COMP 446 / ELEC 446 - Week 5
33
Will / Did
Many lifecycle methods have Will and Did versions
- (void)viewWillDisappear:(BOOL)animated
- (void)viewDidAppear:(BOOL)animated;
- (void)viewDidDisappear:(BOOL)animated;
- (void)willRotateToInterfaceOrientation: …
- (void)willAnimateRotationToInterfaceOrientation:
- (void)didRotateFromInterfaceOrientation:
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
34
viewDidUnload
Called in low memory situations
Only if you are off screen
ARC handles most of what used to be done
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
35
Assignment #3 Questions
SEC - 9/19/12
COMP 446 / ELEC 446 - Week 5
36