The states, counties, and cities are organized into a family tree.
It’s strange that we need two totally different technologies
to navigate the
tree:
a
UITableView
and a
UITableViewController
to move in one direction
(Connecticut → New York → New Jersey)
and a
UINavigationController
to move in the other direction
(state → county → city).
AppDelegate
Model
is a subclass of
NSObject
.
For JSOn format,
see the weather exercise in
Hello.
TableViewController
is a subclass of
UITableViewController
.
tree.json
is a text file.
Main.storyboard
creates the
UINavigationController
.
See the last exercise in
States
for adding a text file (such as tree.json
)
to a project.
The model is a tree in class
Model
.
The
root
of the tree is named “Universe”.
The tree contains sub-trees.
The sub-trees contain of sub-sub-trees,
down to any level.
All of the trees, sub-trees, sub-sub-trees, etc., are called trees.
Each tree is an
array.
The first element of the
array
is a
String
giving the name of the tree.
The remaing element(s), if any,
are the subtrees under that tree.
It’s just like programming in the language
Lisp.
The application delegate creates a
UINavigationController
,
which manages a stack of controllers underneath it.
See
Navigate.
Each controller in this stack
is a
TableViewController
.
Each
TableViewController
has a
UITableView
underneath it.
We never uncommented the
Edit/Done
button
in the
viewDidLoad
method of the view controller.
Model.m
.
Can you add extra levels:
US, Canada and Mexico?
The First Ward, the Second Ward in Yonkers?
tree = BEGIN @"Universe", BEGIN @"iPhone Apps INFO1-CE9236 and INFO1-CE9704", BEGIN @"Hello, world" BEGIN @"The Objective-C language" END, BEGIN @"Create an Xcode project" END, BEGIN @"Create a class of objects" END END, BEGIN @"Still-life 2D graphics" BEGIN @"Japan" END, BEGIN @"Manhattan" END BEGIN @"America" END END, BEGIN @"Collections, touches, and animations" END, BEGIN @"Gesture Recognition" END, BEGIN @"Graphics that respond to a touch" END, BEGIN @"Read and write a file" END, BEGIN @"A control and the target/action pattern" END, BEGIN @"View controllers and CADisplayLink animation" END, BEGIN @"View controllers that manage other view controllers" END, BEGIN @"Special types of view controllers" END, BEGIN @"Nib files and the Interface Builder" END, BEGIN @"View classes" END, BEGIN @"UITableView" END, BEGIN @"UIWebView" END, END END;