How to import contacts from the Address Book - Part 2

Welcome to the second part of this tutorial! At the first part we talked about a couple of things on how to import contacts from the device's Address Book and we developed a demo app to see everything in action. What we really did, was to let us tap on a contact's name, return back to our app and then select specific pieces of information regarding the selected contact, which we displayed on a table view.

In this part what we'll do is going just one step further. We will change a little bit our app and when the user taps on a contact's name a new window will be shown to display specific piece of information. That information will be the e-mail addresses of the contact only. Further more, from the total of the e-mail addresses we'll pick just one by tapping (clicking on the Simulator) on it and that's going to be the e-mail address that we'll display into our table view.

I should also mention that I'm going to base this part of the tutorial on the previous one. That means that I'm going to get the app we implemented into the first part of this tutorial and make some modifications. That also means that, even if you don't want to read the previous part, at least you'll have to get the code and implement the demo app if you'd like to follow up this tutorial. So, I keep going having in mind that you have read or implemented the previous app of our example.

Let's get started.

How to import contacts from the Address Book - Part 1

It happens many times some of the iPhone apps we implement to need access to kind of information imported in ways other than the user's input, or getting data from a file or downloading from the web. A kind of that information is the contacts info existing in the Address Book of the device.

Apple allows to access the Address Book database. That happens not directly, but through a couple of provided frameworks. Even though at the bottom line it's proved easy to fetch contacts info (if you manage to do it once), on the other hand it's not the most straightforward and the most documented part of the iPhone programming that someone may find.

So, in this two-part tutorial, I'll try to explain in simple words how the whole mechanism works and of course, we'll implement a demo app. Before we begin programming, we necessarily need to understand a couple of things. Consider this as a theoretical part before going into practice. I'll try to present it as simple as possible, just to help you get the meaning.

Page Control: Display view controllers as data pages

The Page Control, is a useful tool that allows to display data on an iPhone app in the form of pages. To get the idea, just thing of the main screen of the iPhone, where you navigate among pages to the left and right to display all the apps existing on the device.

To be more accurate, the main idea when you use the Page Control in an app is that you create and use as many instances of UIViewControllers that will display data as the pages you want your app to have. Usually, you need to display various data on the same UIViewController, so it's common to create instances only of one UIViewController. This is what we'll do here, we'll create five instances of the same UIViewController to display all data we need.