Homework using a Navigation Controller

The goal is to install your drawing view (the pentagon) in a navigation heirarchy.

Download this project. It was created from an Xcode template called Master-Detail Application. I have simplified it by removing all references to iPad and a few other things.

In didFinishLaunchingWithOptions you will see that the window has a root view controller which is a Navigation Controller, and it in turn has a root view controller called masterViewController. Try not to let these multiple "roots" confuse you.

The masterViewController is a UITableView controller, and it is set up with one section and one row in that section. The row has the label "Detail". When that row is selected (see didSelectRowAtIndexPath) a detailViewController will be created (lazy creation) and pushed onto the navigation controller's stack, and the view belonging to the detailViewController will appear.

The homework is to take your drawing view and make it a subview of the view owned by detailViewController. To do this you define your drawing view as an instance variable in this controller, initialize it in the viewDidLoad method and add it as a subview. Your drawing view will not need any changes. When the detailViewController is pushed your drawing view should appear. You can add files to a project by simply dragging them into the file panel of the project window. You might prefer to copy the files into the project folder rather than leave them in your previous project.

You will see that the navigation controller uses the top of the window for a title and a Back button. Every view controller has "navigation items" which will be used by the navigation controller to help guide the user from one level to another. See the comments in viewDidLoad and the Navigation Controller reference

By the way, you will see in the xib file a table view with California place names. They do not appear in the xib file or the code, they are simply illustrate that you are looking at a table view.

The page was last updated Tuesday, April 17, 2012 12:08 PM