Furqi
Furqi

Reputation: 2403

how to import contact list from iphone address book to my application?

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.

    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"2.png"] style:UIBarButtonItemStyleBordered target:self action:nil];
    self.navigationItem.rightBarButtonItem = btn;

    self.navigationItem.title = @"Contacts";

    sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,30)];
    sBar.delegate = self;

    [self.view addSubview:sBar];
    sBar.placeholder=@"Search";


    searchedData = [[NSMutableArray alloc]init];

    tableData = [[NSMutableArray alloc]init];

    [tableData addObjectsFromArray:dataSource]; 
}

Upvotes: 5

Views: 926

Answers (3)

Shankar Aware
Shankar Aware

Reputation: 178

The following Quick Start guide from Apple's iOS docs could get you started on this.

Address Book Programming Guide for iPhone - QuickStart

It shows you how to import the AddressBookUI/AddressBookUI.h headers and open a native people picker, as well as listen for when a person is picked.

Upvotes: 1

Manish Agrawal
Manish Agrawal

Reputation: 11026

ABPerson function [ABAddressBookCopyArrayOfAllPeople] will work here.

ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

for ( int i = 0; i < nPeople; i++ )
{
    ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );
    ...
}

After fetching the array of npeople you can display it in your tableView or do whatever you want to implement.

Upvotes: 0

codingNinja
codingNinja

Reputation: 371

You will need to implement the following table delegate method to actually get your table to display data.

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

You can find more documentation on UITableView here

Upvotes: 0

Related Questions