Like we did for the
in Chapter 7, here we’re
going to build some code that you’ll be able to reuse in your own
applications later. We’re going to build a view controller that we can
display modally, and which will display an
MKMapView annotated with a marker pin and can
then be dismissed, returning us to our application.
We can reuse the Prototype application code we built in Chapter 7, which I used to demonstrate how to
use the web and mail composer views. Open the Finder and navigate to the location where you saved the
Prototype project. Right-click on the folder
containing the project files and select Duplicate; a folder called
Prototype copy will be created containing a duplicate
of our project. Rename the folder Prototype3, and
just as we did when we rebuilt the Prototype application to demonstrate
the mail composer, prune the application down to the stub with the Go!
button and associated
pushedGo: method we can use to trigger the
display of our map view (see Sending Email in Chapter 7 for details).
Now, right-click on the Classes group in the Groups & Files
pane, select Add→New File, and select
Cocoa Touch Class from the iPhone section. Create a
UIViewController subclass, leaving the “With XIB
for user interface” checkbox ticked. Name the new class
“MapViewController” when prompted.
At this point, I normally rename the NIB file that Xcode automatically created, removing the “Controller” part of the filename and leaving it as MapView.xib, as I feel ...