Instantiating the View Controllers
project should now contain content for each of the views and all the
view controller classes it needs to function. The classes, however,
still need to be instantiated so that we have actual view controllers
and view objects to use in the application.
MultipleViewsViewController.xib in Interface Builder. This file contains
the parent view that we will be using to for the toolbar interface
element, and it is also a logical place to add our other view controller
Using the Library (Tools, Library), drag a view controller (UIViewController) into the Document window. We want this view controller to be an instance of our FirstViewController class. With the controller selected, press Command+4 to open the Identity Inspector. Use the drop-down menu to choose FirstViewController, as shown in Figure 5.
Figure 5. Update the view controllers to point to the classes you created earlier.
Next, the view controller must
be updated to point to the correct XIB file (FileViewController.xib) for
its view. Select the controller in the Document window and press
Command+1 to open the Attributes Inspector. Within the NIB Name
drop-down menu, choose FirstViewController, as shown in Figure 6.
Figure 6. Associate every view controller with the appropriate XIB file.
Repeat these steps for the SecondViewController and ThirdViewController
classes. (That is, add a new view controller instance, set the class,
and associate the view.) When finished, your
MultipleViewsViewController.xib should look very similar to Figure 7.
Figure 7. Add three view controller instances to the XIB file.
With these changes, our
project will build and instantiate the controllers, but there is still
no way of displaying the different views. It’s time to add the toolbar
controls and code to make that happen!