Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 4. Core Location and Maps > Creating a Map Using Interface Builder

recipe 4.2. Creating a Map Using Interface Builder

4.2.1. Problem

You would like to use Interface Builder to create a map control.

4.2.2. Solution

Use Interface Builder to add a map view to one of your application’s objects (usually a view). By adding it to an XIB file, you create an MKMapView object that can be accessed by your program.

  1. Choose an XIB file to host the map. Normally, we use a View XIB file, which comes with a view attached to the XIB file by default. If you already have an XIB file, skip to step 2. To create a new XIB file, in Xcode choose FileNew File. In the New File dialog, on the left side, choose User Interface and then, based on your need, select whichever type of XIB file you would like.

  2. Once Interface Builder has opened the XIB file, select ToolsLibrary to open the Library pane.

  3. In the Library pane, find the map view and drag and drop it into your XIB file.

4.2.3. Discussion

Now that you have an instance of the MKMapView object in your XIB file (as shown in this recipe’s Solution), you can navigate to the Connections Inspector pane in Interface Builder by selecting ToolsConnections Inspector. Select your map object and you will see that the Connections Inspector allows you to see the delegate and the new referencing outlet connections of your map view. You need to drop the new referencing outlet to an IBOutlet of type MKMapView in your header files and drop the delegate connection to an object in your XIB file that implements the MKMapViewDelegate protocol.

4.2.4. See Also

Section 4.3

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint