Lab 6 - View Controllers
Objectives
- Use view controllers
- Use a navigation controller to switch between views
You will create an application that displays static data that displays a list
of friends. You will allow the user to navigate to see additional detail.
- Create a new project using the Window-Based Application template.
You can then create a UINavigationController in your MainWindow NIB or in
code using the -init method. You will need an instance variable in
your application delegate referencing the navigation controller and don't
forget to release it in the appropriate place.
Since UINavigationController is a UIViewController, it has a view property
that you can access. Add this view to the window using the -addSubview
method. Run your program and
see what happens.
- Select New File... and use the UIViewController subclass file template.
This will create quite a few methods already but we will not need them so
delete them file the .m file. Name this class PersonListViewController.
This will also create a nib.
- In IB lay out your static list of people using labels, buttons, and
image views. Each person should be displayed with a picture, name, and
a button, that will allow users to get more information when it is fully
implemented.
- Create an instance of the PersonListViewController in your application
delegate (with your Navigation controller). Use the -initWithNibName:bundle
method, passing the name of your IB document as the first argument (without
the file extension) and [NSBundle mainBundle] as the second argument.
- Push the view controller onto the navigation controller's stack so that
it is displayed. You can build and run at this point.
- Create a second view controller subclass and nib. When a button in
your list is touched, push an instance of this second view controller.
The view should display the picture and name as well as some additional text
for that person. You will want to display a helpful title in the
navigation bar when each view controller is being shown. Also, make
sure that you do not leak memory.
You will want to create a custom init method for this view controller where
you supply the data for the view controller as parameters. The UIImage
can be obtained from a file path and the method -[UIImage imageWithContentsOfFile:].
You will need an IBAction in the PersonListviewController for the button
pushes and this method should check which button is the sender to create the
appropriate detail view.
- Compress your project and send it to me through the Dropbox in
BlackBoard.