Notes on iOS App Development

prettybadelyngeSoftware and s/w Development

Nov 18, 2013 (3 years and 6 months ago)

139 views

Page
1

of
13

Notes on
iOS

App Development

Created

12
/08/09

Updated 01/03/10
, Updated 04/16/10
, Updated 08/08/10
, Updated 09/23
/10
,
Updated 01/10/11
,
Up
dated 02/28
/11

Updated 05/1
3/11
,

Updated 12/02/11
,
Updated 01/20/12
, Updated 02/04/12
,
Updated 08/25/12
, Updated 10
/24
/12

Updated 02/26
/13
, Updated 03/12
/13
,
Updated 03/31
/13
, Updated 04/07
/13
, Updated 04/13/13
, Updated 05/11
/13

Introduction

Th
ere are two approaches to iOS

app development: Native applications and “Web App” applications.
A native
application means that i
t run
s on the iOS operating system, while a “Web App” runs on the browser supported by
the iPhone.

This document focuses entirely on native applications.


Native development for
iPod touch,
iPhone
,

and iPad development is

done in Objective
-
C, with the X
co
de IDE.



T
he current version of IOS is 6.1
, released in
early 2013
. The prior version, current during late 2011 through mid
-
2012, was 5.1.1.

Native App
Development Resources

There are online courses for iPhone and iPad offered
http://www.edumobile.org/coursedetails.html
. These are
online workshops that run for 6 weeks, with online lectures and support. The content is very similar to the Paul
Hegarty courseware.


“Programming iOS6: Fundamenta
ls of iPhone, iPad, and iPod Touch development

(3
rd

edition)
” by Matt
Neu
burg.
O’Reilly Press, March 2013, 1000

pages. Just releas
ed
.

There is
a preview copy at
http://www.apeth.com/iOSBook/



iPhone and
iP
ad Application
Programming
” downloadable Stanford
Course

by Paul Hegarty

from iTunes U.

Created in

2010 and
updated for Xcode 4 and updated

to

iOS
5
in
late
2011.

Updated to iOS 6 in early 2013.


“Programming iOS5: Fundamentals of iPhone, iPad, and iPod

Touch development

(second edition)
” by Matt
Neu
burg. O’Reilly Press, March 2012, 1024 pages. List price $49.99, Amazon price, used from $31.36, used
from $21.99. Rated 4.2 stars on Amazon.com. A timely update to a well
-
received book.

Link
http://proquest.safaribooksonline.com/book/programming/mobile/9781449365783



“Beginning iOS 5 Application Development” by Wei
-
Meng Lee. Wrox Press, January 2012, 656 pages
. List
price

$39.99, Amazon price $23.22, used from $6.79. Rated 2.9

stars on Amazon.com.

While the writing is clear,
and the illustrations clear including use of full color, comments indicated that this was a minor update from the
author’s prior book o
n iOS 4 development, and hence didn’t cover many key concepts.

Available in electronic
copy from City of Palo Alto Library.


“Learning iPhone Programming (second edition)” by Alasdair Allen. O’Reilly Press, March 2012, 430 pages.
List price $34.99, Amaz
on price $23.
79, used from $6.53
. Rated 3

star
s Amazon.com. While it appears to be a
good book to learn from, comments were mixed. Reviewers didn’t like the writing style, for instance. This was
apparently
not improved in the transition to the second e
dition
.


“iOS Programming: The Big Nerd Ranch Guide (second edition)” by Joe Conway and Aaron Hillegas. Big Nerd
Ranch Press, July 2011, 529 pages. List price $49.99, Amazon price $31.06, used from $25.00. Rated 4.5 stars

on
Amazon.com. One of the fir
st
books that covers Xcode 4.
C
omprehensive and well
-
written.

Available online at
Palo Alto Library.



Programming

4:

Fundamentals

of iPhone, iPad, and iPod Touch development”

by Matt Newburg
. O’Rei
l
ly
Press,
June
2011
, 834 pages
. List price $49.
9
9, A
mazon price, used from $39.3
6, used from $22.99
. Rated
4.
5
stars on Amazon.com.

One of the first books

that covers Xcode 4.

Page
2

of
13



Head First iPhone and iPad Development” by Dan Pilone and Tracey Pilone.
HeadFirst/
O’Reilly Press,
June
2011
, 674 pages
.

List
price $49.99, Amazon price $30.07, used from $2.79. Rated 3.5 stars on Amazon.com.
Comments were
positive

on the writing style, but pointed out that it is dated because it uses Xcode 4.2 and iOS4.
There is a 3
rd

edition coming out in May 2013.

Developme
nt Concepts

It is much like developing in Flex or for a

Macintosh: you use a not
-
quite
-
C++ system, have a set of visual
components, have an interface builder, and have a runtime that provides many callable functions for integration,
data management, OS to
ols, and more. Plus there is a simulator and a debugger that runs on your development
system.


The
development system uses

X
code from Apple, which is
an IDE much
like Eclipse.

See our document “Notes
on Xcode”.

Stanford Class Series by Paul He
garty: Cla
ss Schedule

See
https://itunes.apple.com/us/course/coding
-
together
-
developing/id593208016


Lecture 1
:
MVC and Introduction to Objective
-
C

(
January 8, 2013
,
T
ime
abo
ut
1:10
)

Class intro, background requirements (must understand O
-
O terminology and concepts)

Concepts of MVC

-

separation of roles

-

d
elegation


Basic concepts of Objective
-
C

-

classes, messages, selectors

-

single inheritance, but you can add protocols (like mixi
ns)

-

no garbage collection in iOS, instead reference counts are used

-

All objects inherit from NSObject, and this provides a set of run
-
time
-
type
-
indication checks.

-

NSString is probably the next most important object class. Used instead of char*

-

Other impor
tant objects are NSNumber, NSDate, etc


Lecture 2
:
Xcode 4 (January 10, 2013
, Time about 1:13
)

Continues

with concepts of Objective
-
C

-

The message send syntax is [<obj> <message> <args>]

-

Note that all message dispatching is determined at run
-
time. The com
piler doesn’t make checks on this.

-

There are naming capabilities for messages that include elements of each argument in the name.

-

Selectors list all of the message signatures which are processed by a given object or class.

-

alloc and init are separate metho
ds, but you should always call them together

-

nil means null

-

it is common to lazy initialize objects

-

local variables are initialized

-

iOS 6 has an array
-
like access method with square braces

-

there is printf
-
like notation

-

%@ will print an object, by running t
he “description” method on the object

-

if you implement both set and get on a property, you have to specify @synthesize

-

methods with ‘
-
‘ are on instances, methods with ‘+’
a
re on classes

-

‘id’ means ‘pointer to an instance of any class’


Xcode introduction

-

S
tarts running Xcode
. T
his is Xcode 4.

-

There is a detailed walkthrough in the slides

-

We will always use storyboards in this class

Page
3

of
13

-

Describes building a app that displays one card of a deck (the homework assignment is to implement the
model, and display all
cards of the deck)

-

The app is called Matchismo (it is a card
-
m
atching game)

-

Select iPhone 4 configuration (called Retina 3.5 in the dimensions screen)

-

Turn auto
-
layout off (this is new feature, not covered in class)
. This selector is located on the Utilit
ies
panel in the properties for the .xib file

-

All of the ui is built graphically

-

AppDelegate can be moved to supporting files

-

Click “tab” to accept the code completion string

-

Groups in the navigator are unrelated to directories on the file system.


Lecture

3: Objective
-
C

(January 15, 2013
,
Time about 1:14
)

T
his lecture extends the concepts

introduced in Lecture 2. I
t is mostly a long demonstration
, rather than being a
set of slides about Objective
-
C

-

Build the infrastructure for a matching game

-

Need to hav
e a set of cards
, and a match system

-

Matching is determined by the kind of card

-

Discussion

about
actions

and outlets

o

Actions are the view talking to the controller

o

Outlets are the controller talking to the view

-

Outlet collections

-

Create a “designated init
method” in most of your classes

-

Implement the match logic

-

Keep track of the number of flips and the player’s score


Last part: here Paul summarizes what students should
understand

as of this point:

-

MVC

o

What it is about

-

Xcode

o

Create project, add files

o

Edit

files, run the simulator

o

Use the documentation

-

Objective
-
C

o

Must know the basics: classes, properties, etc.

o

Types, methods, allocation on the heap

o

NSObject, NSString, NSArray

o

NSLog is a great way to debug


Assignment 1: Matchismo

-

first, re
-
create the app
lication that Paul showed the construction of during the video

-

add more buttons. This was easy

-

add a message indicating what happened when clicking on a card. One new field created with IB,
updates from Game class

-

add “deal” function. This rebuilds the
Game and Deck

-

add selector for switching between 2
-
card match and 3
-
card match. This is a new parameter, and a new
type of visual control
, the UISegmentedControl

-

c
hange buttons to have an image on their back
. The image is loaded in “updateUI” method, and

assigned
to
the buttons which are face down by using


[cardButton setImage:cardBackImage

f
orState:UIControlStateNormal];



Lecture 4:
Foundation,

Attributed Strings

(
January 17, 2013, Time about

1
:18
)

Foundation refers to the package

of classes that all apps are based on.

These include NSArray and NSMutableArray

with all of their provided methods. We’ve been using many of
them.

You can dispatch to the class of an object by using [<object> class]. This may be useful for code within a

class
library, for instance.

Page
4

of
13

In general if a method has the word “copy” in it you will get a new object, otherwise you will get a pointer to an
existing object.

Discussion covered the dynamic typing model in Objective
-
C: all message dispatches are looked

up at runtime, so
a pointer to classed object generates the same code as a
n

“id” (unclassed
pointer
)
. You
*
can
*

send messages to
nil. However, if your object or its superclasses doesn’t have a handler for a given message, you will get a crash.

The compi
ler will create warnings when calling a message on a specific class when the message doesn’t exist.

The compiler may create warnings when unusual casts are being used.

Don’t think about void* when using object.

Introspection: isKindOfClass, isMemberOfClass

(no inheritance), respondsToSelector (this takes
@selector(<name>) as an argument)

Nothing like Java’s templated collections


everything is generic

“makeObjectsPerformSelector” can be applied to a colle
c
tion (NSArray)


Improve the matching in Matchismo
,
by using introspection to confirm that an object is a PlayingCard.


Foundation:
Other important classes include
NSDictionary (hashtable),
enumerations, property lists.

Most classes
implement “description”, which is like toString
()

in Java.

NSNumber is a w
rapper around the primitive types such as int, double, etc.

NSData is raw data (bag of bits)

NSDate is date abstraction.

NSSet and NSOrderedSet

NSDictionary is one of the most important classes. There is a new iOS6 syntax to create/populate these which is

similar to JavaScript maps.

Property list is just only object graph that only has NSString, NSArray, etc. in it. A dictionary is a property list if
all of the keys and values are property lists.

NSUserDefaults is a property list that is stored per
-
user.

Sticks around even after your application quits.
Remember to call “synchronize” after making changes to the content.


Attributed Strings are strings which include a property list for each character. The properties can include color,
font, background, et
c., with these elements corresponding to the PostScript imaging model.

To use attributed strings, create a Label object, and change the type from Plain to Attributed.


Lecture 5: View Controller Lifecycle
and Multiple MVC’s
(
January 23, 2013,

Time about

1
:11
)

Another author’s similar notes on this lecture are located at
http://blog.yanz.net/2013/03/ios
-
programming
-
cs193p
-
lecture
-
notes
-
2/


The lecture begins with the obser
vation that
a typical application is composed of many MVC’s. Typically one for
each screen or set of screens.



MVC’s are most ofte
n initiated out of a storyboard
View controllers can be created with alloc init
but very rare

What happens then: 1) Outlet s
etting, 2) Appearance and disappearing, 3) Geometry changes, 4)
Low
-
memory
situations.


At each stage, iOS invokes method(s) on the controller
.

After instant
ia
tion and outlet
-
settings, viewDidLoad is
called
.
It is a good place to put setup code
.


awakeFr
omNib is called for all objects that come out of the storyboard. This is because the storyboard uses a
difference strategy for alloc and init.

You rarely have more than one storyboard, instead you have a large one.


To use
Multiple MVCs

Simplest situatio
n: UITabBarController

Many other situations
: 1)
Segues (touches in the View of one MVC causing another MVC to appear on screen)
,

2)
iPad Split View
, 3)
Navigation Controller

4)
Modal Controller

1.
How to create another MVC

2.
Drag a scene for the MVC from o
bject palette into storyboard

Page
5

of
13

3.
Set the class of the MVC in the Identity Inspector

4.
Create the new UIViewController subclass with New File…


Build the View and wire up outlets and actions to the controller with ctrl
-
drag


Multiple MVC’s are used on the
different panels of a multi
-
panel application
.

The lecture includes an example of adding a
UITabBarController object

to a simple version Matchismo
. Similar
materials is available from Apple at
http://developer.apple.com/library/ios/#documentation/WindowsV
iews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html

If there are more than 4 tabs, “More” is automatically generated.


“Scene” means “controller and view”


If you have an existing view, and want to make it into part of a tab
-
bar
-
based app
lication, you should create a tab
-
bar controller on the storyboard. It will come with linked child views, which can be deleted, then you wire up the
ones that you want.


You do need to make the UITabBarController’s scene be the default one (otherwise you
get a warning).


Demo session: adding a score panel to Machismo. This also includes use of property lists as way to manage
information.

Also formatting a date, and sorting by scores.

UITextView is like a UILabel but with ability to scroll, wrap and edita
ble

(we can turn this off)
.

UILabel is usually used for one or two lines of text.


The text view will contain content that is a record of game scores, in addition to having a set of buttons that
controls the sorting. The sorting isn’t done in a table, it
is carried out in memory and then a list of strings is
created.


By c
reating
the
GameResult
class Professor Hegarty shows us

how to create a custom class then save
its

data to
NSUserDefaults and then retrieve it.

NSUserDefaults only accepts plist and beca
use of that you have to store the
properties

in nsdictionary before adding it to NSUserDefaults.

He then used a class method to retrieve the data
and store them back in game results.

The interesting part is when he created a
convenience

initializer

that
accepted

pList and which
initialized

the class with that data.

This way you can get game results anywhere in your
application with out much work.


Difference

between the
game
time
s

is stored in NSTimeInterval
.


The professor is posting a new version of th
e code that includes all of the elements that were demonstrated,
including completion of the formatting and sorting.


I integrated this on 04/13. A really useful example: multiple views, uses PropertyLists to set up NSUSerDefaults
and these are maintaine
d in the simulator state. Each game is recorded in one GameResult, and a new GameResult
is made for each game, because he sets the gameResult variable to nil in the Deal method.


Assignment 2:

Set

About to start on this
: requires creating multip
le views

and controllers. The S
et game has different cards and
rules. Try to re
-
use as many classes as possible.


Lecture 6: Views and Gestures (January 25, 2013,

Time about

1
:18
)

Up until now, our views were basically frames upon which components such as butto
ns and labels were place.
However, by subclasses UIView, one can draw on the canvas, and the iOS framework includes a sophisticated
graphics model.


A view (i.e., UIView subclass) represents a rectangular area. You can draw and handle events in that area
.

Views can be nested hierarchically (each with one superview, and can be many subviews). Subview order matters,
those later in the array are on top of those earlier.

Page
6

of
13


UIWindow is the one at the top of the view hierarchy, typically only one in an applicat
ion. The hierarchy can be
constructed in Xcode (interface builder) or can be done in code.


The @property “view” represents the top, and will have top
-
level events dispatched to it. Automatically hocked
up when you drag out a View Controller in Xcode.


Y
o
u may want to perform initialization on a UIView: initWithFrame is not called, but awakeFromNib is.


Next, a discussion
about the CoreGraphics framework
, such as the CGFloat, CGPoint, CGSize, and CGRect
typedefs. These are
structs (the graphics system u
ses C rather than Objective
-
C).
0,0 is in the upper left, and
coordinates are measured in “points”, creating a level of device
independence
.


Views have three properties related to their location and size: bounds, center, and frame


Drawing on the canvas

is easy: create a UIView subclass and override the drawRect method. This method will be
called the framework, never call it directly. Instead, tell the framework what area needs redisplay by calling
setNeedsDisplay() or setNeedsDisplayInRect(rect).


To

get the graphics context, call UIGraphicsGetCurrentContext()



never cache this.


You can draw rounded rects and
ovals, but internally, all
drawing operations work on Bezie
r paths.

These can be
filled and strokes. You can build up the path yourself, or
ask for a rounded rect or oval path. This is highly
influenced by PostScript or NeWS.


There is support for transparency, and for hiding and showing views.

You can also push and pop graphics state.


For text, you can use UILabels on your views, but you c
an also draw text directly on the canvas, and fetch
information such as fontMetrics and text size.


There is support for drawing images.


Autolayout: when your bounds changes, you subviews also get re
-
layed out. In iOS6 there is a system based on
constra
ints, but the earlier system was built on struts and springs.

These define the

grow


and

shrink


behavior.


Gestures include

dragging, resizing, etc.

These are how you get touches. Gestures are recognized by the class
UIGestureRecognizer. You typical
ly add these to a UIView programmatically. Then you write a handler for the
specific gesture (such as pan, swipe, pinch, tap)


How do we implement the target of a gesture recognizer: 3 methods:
translation, velocity, and setTranslation.
Also there is a

state, such as Began, Failed, Changed, and Recognized. Think of the recognizers as observers that
watch the event stream and seek to find patterns.


Within the pan behavior, for instance, you can get the cumulative or incremental distance.


The various r
ecognizable gestures have attributes such as



scale and velocity for pinch



rotation and velocity for rotation



direction and number of touches for swipe



number of taps required for tap


If you are creating a highly visual game with sophisticated interaction
, you will be dealing with the lower
-
level
gesture recognizer implementation.


Demo session: drawing a playing card

(there is a downloadable demo called SuperCard)

Page
7

of
13

Creating a custom UIView with its own drawRect method, using Bezier paths, managing graphic
s context, using
gesture recognizers.

This was a really good example, as it started with a simple UIView class, then added more
and more drawing operations on top, which in turn used most of the graphics operations discussed. At the end, the
swipe gestur
e was used to turn over the card, and the pinch gesture was used to change the scaling of the image on
the face cards.


There is also a Friday lecture on 1/26/13, which covers running apps in your actual device, but the Friday sessions
are not provided on
iTunesU.


Lecture 7
:
Protocols and
Collection

Views
(January 29
, 2013,

Time about

1
:18
)


Protocols are like interfaces without implementatio
n. They improve on use of ‘id’, which is too generic a
qualifier.


Think of it as a syntactical modification of id
, for example “id <MyProtocol> obj”. Now we know that obj can be
of any class, but that it implements some methods.


The syntax is:

@protocol Foo

-

(void)someMethods;

@property



@end

Anyone implementing this protocol must implement all of these methods.

However, you can also mark some as
@optional.

NSObject is a protocol. Of course, the NSObject class implements the NSObject protocol.

You put @protocol definitions in header files.

Your classes can say they promise to implement the protocol.

You can also

declare arguments to a protocol.

Just like static typing, this is all compiler
-
helping
-
you stuff. Think of it as documentation for your method
interfaces.

#1 use of protocols in iOS is for delegates and datasources. Best learned by example: we will see

this in the
UICollectionView.


UICollection
View
is a UIView which lays out little boxes filled with other views repeatedly. Think of it as
managing

subviews or panels.

UICollectionViewFlowLayout


is the default layout mechanism. Lays out little boxes fi
lled with views like they
were characters in a stream of text, including wrapping and justifying them.

UICollectionViewCell


this is the little box that gets repeated.

Examples: we will use the Collection View for this example.

Here is where protocols co
me in: UICollectionView is part of the View so it can’t own its data, so it will ask a
datasource for the data behind the cells.

There are some complex steps in InterfaceBuilder to get this right.


Let’s look at the methods in the UICollectionViewDataSour
ce protocol


this is like a mixin that defines classes
that your data source must implement in order to be usable by the collection view:



numberOfSectionsInCollectionView.



cellForItemAtIndexPath


here we deque a cell
. This leads to a discussion about re
using cells.
In fact, the reuse identifier is first introduced here.



viewForSupplementaryElementOfKind


this allows for creating headers and footers.

What can you do by sending messages to the UICollectionView itself? reloadData, reloadSections, deleteI
tems,
insertItems, determine what cells are visible, also track gestures.

Things you can Inspect about a UICollectionView in Xcode:



flowDirection



sizing

Page
8

of
13

what is the delagate: allows you to add business logic, such as ability to track/control the selection
and hiding of
cells.

To aid in use: here is a UICollectionView checklist:



wire up view to outlet in controller



add the protocol to one of your controller’s interfaces



wire up the datasource with ctrl
-
drag from UICollectionView to your controller’s icon in
Xcode



Create a subclass of UICollectionView if you want outlets/actions from view inside it



Set the subclass of the UICollectionViewCell in the identity inspector



Set the reuse identifier



Use that same reuse identifier when you deq
ueue in the collec
t
ionVie
w:cellForItem
AtIndexPath



Use introspection, then cast to get your UICVCell subclass right in the above method


Demo session: pretty Matchismo demo: integration of the PlayingCardView from last time into Matchismo


The homework assignment is to create a gr
aphical version of your Set Matchismo
project
using custom UIView
and UICollectionView.


Lecture 8:
Autolayout and Navigation
(January 31, 2013
, Time about 1:17
)


Autol
ay
out is a way to define a scre
en that looks good on different

devices and device orien
tations.


How do we set the constraints in Xcode?

These are done with the “blue guides” that we see when we move and resize things, then editing the properties.


First, turn autolayout on. Then a bunch of purple things have appeared on the Document outlin
e. They are
NSLayoutConstraint objects.


We can specify what objects are used as the layout reference for another. For instance, you might work from the
center out, or from the upper left on downwards. Each constraint allows for minimum and maximum gap
sizes,
centering, etc. You should avoid having specific numbers in your constraints, as these will probably be language
specific (Paul points out how German words tend to be longer than others). In most cases you want “0” or
“Default”.


You can specify p
riority of constraints. 1000 means mandatory.


A purple constraint indicates: “you have to have this one or the constraints won’t be sufficient to decide where
things go”. A blue constraint is called a “User Constraint” and can be deleted.


If a constra
int is purple, it is possible promote it to blue so you can delete it, but Xcode will probably just add it
right back as purple if the constraints are not otherwise sufficient for the layout.


When there are several views (components) competing for the sam
e space, you will need to indicate which of the
candidate views should compress and which should take up the available space.

The setting is “content hugging
priority”.


Now we can test by running within Xcode and simulating various layouts. This is done

on the Attributes
inspector, and simulated metrics include “Size”, “Orientation”, the presence of the status bar, top bar, bottom bar,
etc. In the slide presentation Paul shows the Matchismo game with the bottom buttons and labels in the right
locations
even when in landscape orientation.


The “inferred” bottom bar means “figure out from what’s going on in the storyboard. Since, in this storyboard,
our View is hooked up to a Tab Bar Controller, Xcode will infer that it should be a Tab Bar at the bottom.


Other layout tests would include using the iPhone 5 sizing.


Page
9

of
13

Mastering autolayout takes experience, there is simply no substitute for this.


Second part of lecture:
The navigation improvements are built around the UINavigationController class, which
poin
ts to one of a set of MVC’s. It typically offers the MVC’s through a scrollable,choosable list. If you have
moe than 4
-
5 such MVC’s, this is an improvement over the UITabViewController.


UINavigationController follows the seques. This is the first time
that we have paid much attention to them (the
ones used in the TabViewController were pretty much defaulted). Each seque has an identifier, and a type (style).
You can embed a ViewController in a UINavigationController by selecting the View controller, t
hen choosing
Embed In > NavigationController from the editor menu.


Notice that the Views got little bars put on the top of them when they become embedded. This is an automatic
feature of the UINavigationController.


Now let’s look at the “parts” of a UIN
avigationController. First there is a view obtained by the navigation
controller using the view property of the UIViewController, that was most recently pushed with a Push seque. The
title is obtained dynamically, and there can also be an array of toolba
r buttons. Plus there is a link back.


You can push and pop as needed, either based on events from the UI, or programmatically.


The ViewController also supports other kinds of seques besides Push. These include: Replace, Popover, Modal,
and Custom.


Y
ou can fire off a seque from code. You can prevent a seque from happening. There is also a way to unwind
from a series of seques.


Demo session: Card Viewer (application with a second MVC which is sequed to in a Navigation Controller).

Then if time perm
its, we will run through the autolayout slides.


No Friday lecture this week.


Lecture 9:
Scroll View and
Table View (February 5, 2013, T
ime about 1:15)


Here we are getting to some of the most important and useful view classes. The
UIScrollView

is used
for creating
a region on the screen that is a pannable view into a larger area, such as a large image.


How to you create one: drag out in a storyboard or use alloc/initWithFrame. Or select a UIView in your
storyboard and choose “Embed In
-
> Scroll View”

from Editor menu.


Don’t forget to set the contentSize: common bug is to forget scrollView.contentSize = imageView.bounds.size;


You can control: whether scrolling is enabled, locking scroll direction is user’s first move, style of scroll
indicators, whe
ther the actual content is “inset” from the scroll view’s content area.


Supports zooming.


Lots and lots of delegate methods: keeps you up
-
to
-
date with what is going on. Only one mentioned in class was
scrollViewDidEndZooming.


The
UITableView

combines
elements

we have seen within

the
UICollectionView class
, including the aspects of
cells, scrolling, sections, headers, footers, etc.

Interestingly, the TableView is subclassed off of ScrollView, and is
a separate implementation from CollectionView (which
wasn’t introduced until iOS 6).


The TableView can be Plain or Grouped.


Page
10

of
13

The TableView can have static cells or dynamic cells (in which case there is a dataSource being used). A given
cell in a table view
(which must be a UITableViewCell or a subclass of
such)
can have
a cell type (or “
style
”)
, and
can have a link to seque to another screen. The Xcode project template “Master
-
Detail” is a TableView for the
master view, and then a mostly blank area for the detail.


If you set “static cells” mode, the Table
View will still talk to its datasource, so don’t give conflicting information.


Some cell styles can have an image. We have seen this in several apps.


The TableView and its related protocols (for
delegates and
dataSources, etc.) has too many methods to c
over them
all in the Stanford class.

Remember: the delegate is used to control how the table is displayed, the dataSource
provides the data that is displayed inside the cells.


The cell re
-
use system is similar to what we have seen in CollectionView.


Th
e delegate
also lets you observe what the TableV
iew is doing. Especially when the user selects a row.


You can seque when a row is touched, just like from a button.


The demo this week is called Shutterbug, and is a way to browse photos on Flickr.


The ho
me is called SPoT, which is a more advanced app for viewing photos

on Flickr
.


Lecture 10:
UI Toolbar,
iPad, B
locks
, and intro to Multithreading

(February 7, 2013, Time about 1:1
2
)


UIToolbar


allows you to place a set of buttons at the top or bottom of
the UI. Examples include the buttons that
appear at the top of the Book
-
viewing application. The UINavigationController is typically in control of this
object,
and the toolbar is constructed out of UIBarButtonItem objects.


You can control the left
-
right

alignment of the buttons by using the flexible space attributes. Item styles include
plain style and bordered style.


A “Universal” app is for
both
iPhone and iPad.

You can programmatically determine if your app is on an iPad by
calling [[UIDevice curre
ntDevice] userInterfaceIdiom and comparing with UIUserInterfaceIdiomIPad.


You can also fetch the screen bounds, to aid in layout operations.


The UISplitViewController gets discussed next, as it is iPad
-
specific.


Popovers are another iPad
-
specific feat
ure available to developers.


Blocks are a concept of Objective
-
C that we haven’t discussed yet.

Like a “closure” in Groovy.

You must keep
track of stack/heap allocation within the boundaries of a block.


When do we use blocks: enumeration, view animati
ons, sorting, notification, error handlers, completion handlers.
And they are very important in multi
-
threading.


Multithreading



built around Grand Central Dispatch.

Projects from Earlier Versions of the Paul Hegarty Class

Calculator

This was an example

of the role of the model, view, and controller classes, plus using the Interface Builder
, taught
during the Winter 2011 term
. The problem was to implement a calculator that would accept digits being pressed,
perform operations, and handle memory and trig

functions.

While it was a good example of the UI, the amount of
Page
11

of
13

information in the model was rather little, and in

particular it didn’t use many data structures other than just strings
and ints, no subclassing.


We implemented this during December 2011,
and then re
-
implemented in March 2013.

RPN Calculator

This was a revised version of the calculator project, taught during the Winter 2012 term. It was a better example
of the model
/view/controller concepts
, as it allocated a stack, and then some of the pr
ogramming extensions were
to support variables, and even code scriptlets.


We implemented this during early 2012, and then re
-
implemented in March 2013.

Chapters in “iOS6 Programming” (
Matt Neu
burg, O’Reilly Press)

Section 1:

Language

Chapter 1: Introduc
tion to Objective
-
C

Concepts of Objective
-
C and Object
-
Oriented programming.

Section 2:

IDE

Chapter 5: Introduction

How to get around
in
Xcode.

Section 3:

Cocoa

To be filled in

Section 4: Views

Chapter 11: Introduction


Chapter 18:
Using the Table Vi
ew

A table view (UITableView) is a scrolling interface (a vertically scrolling UIScrollView,
Chapter 20
) for
presenting a single column of rectangular cells (UITableViewCe
ll, a UIView subclass).

It is a keystone of Apple’s
strategy for making the small iPhone screen useful and powerful, and has three main purposes:


Presentation of information

The cells typically contain text, which the user can read.

The cells are usua
lly quite small, in order to
maximize the number of them that appear on the screen at once, so this text is often condensed, truncated,
or otherwise simplified.

Selection

A table view can be used to provide the user with a column of choices. The user cho
oses by tapping a
cell, which selects the cell; the app responds appropriately to that choice.

Navigation

The appropriate response to the user’s choosing a cell is often navigation to another interface. This might
be done, for example, through a presente
d view controller or a navigation interface (
Chapter 19
). An
extremely common configuration is a master

detail interface, in which the master view is (or contains) a
t
able view, often at the root of a navigation interface; the user taps a listing in the table to navigate to the
details for that choice. This is one reason why truncation of text in a table view is acceptable: the detail
view contains the full information.



Table cell styles:




Default


shows the labelText



Subtitle


this shows the detailLabelText as well as the labelText

Page
12

of
13



Value1


labelText in black left aligned and the smaller detailLabelText in blue, on the same line
and right aligned



Value2


labelText
in blue on left side of
cell, right aligned and detail
LabelText on right of cell,
left aligned and black


In addition to its column of cells, a table view can be extended by a number of other features that make it even
more useful and flexible:



A table can

start with a header view at the top and end with a footer view at the bottom.



The cells can be clumped into sections.

Each section can have a header and footer, and these remain
visible as long as the section itself occupies the screen, giving the user
a clue as to where we are within
the table.

Moreover, a section index can be provided, in the form of an overlay column of abbreviated
section titles, which the user can tap to jump to the start of a section, thus making a long table tractable.



A table c
an have a “grouped” format. This is often used for presenting small numbers of related cells.



Tables can be editable: the user can be permitted to insert, delete, and reorder cells.

Working with JSON

See
http://www.raywenderlich.com/5492/working
-
with
-
jso
n
-
in
-
ios
-
5

Problems
Encountered

Mismatch of iOS versions with the xib files.


“Not keyed error”

this means that the xib doesn’t have the identifiers that the app is expecting, or vice versa. This
throws an exception at start up.

Projects Worth Keeping

Gam
ma


this

shows a multiple panel application, with graphic elements on one panel and
animation

elements on
another
.
Uses a storyboard.
From an online tutorial.


TableExample


simple table example


BirdSightings



from Apple example


Calculator



Paul
He
garty

2011 example


RP
N
Calculator


Paul Hegarty 2012 example


Matchismo


Paul Hegarty 2013 example

Chronology and Corres
pon
dence

Feb

26,

2013: Thank you for registering as an Apple Developer.


Now that you've registered as an Apple Developer, you can u
se your Apple ID, jrisberg@aol.com, to access all
kinds of helpful resources on the Apple Developer website:



Resources for Apple Developers



Downloads for Apple Developers



Development Videos


March

8,
2013: Completed 3

tutorials on Xcode and iOS 5
/6
.

M
arch 11, 2013: completed first JSON
-
fetch example. However, didn’t get too far on displaying the challenge
structure, as we needed
to learn more about the use of T
able
View
s in a master
-
detail structure.

Page
13

of
13

March 16, 2013: Completed the second tutorial pro
j
ect from Apple, about logging b
ird sightings.

This was a
master
-
detai
l TableV
iew app.

March 24, 2013: completed the Calculator
and RPN Calculator
example
s

from Paul Hegarty
’s course materials
.

March 30, 2013: read several chapters of the Neuberg book.

M
arch 31, 2013: completed lecture 3 from
Paul Hegarty’s course materials

April 3, 2013: started lecture 4
, and began work on assignment 1

April 7, 2013: with lecture 4 and assignment 1 now done, we have completed work on “foundation
-
level” material
and c
oncepts of Objective
-
C. From this point forward we began a walk through the various features of iOS
applications, such as tabs, views, gestures, etc. Using a tab bar is the current area to learn more about.