2011-05-27 55 views
0

我正在开发一个应用程序,并且我必须打开地址簿,我已经使用ABPeoplePickerNavigationController来打开地址簿,并在其中存储了所有电话号码和电子邮件用户,但是我并不知道如何存储电话号码或电子邮件的价值,假设用户点击电子邮件字段时,电子邮件地址存储在某个变量中,并且如果点击电话号码存储在另一个变量中。如何选择iPhone中地址簿中的特定字段

回答

2

你好请找到下面的代码......

你可以从你的iPhone通讯录获取名字,姓氏,人的形象和移动电话号码

Add按钮将你的ViewController并添加该代码到你的按钮点击事件。

-(IBAction)btnGetNameClicked:(id)sender { 
     // creating the picker 
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; 
    // place the delegate of the picker to the controll 
    picker.peoplePickerDelegate = self; 

    // showing the picker 
    [self presentModalViewController:picker animated:YES]; 
    // releasing 
    [picker release]; 
} 

-(BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { 

    // setting the first name 
    lblFirstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 

    // setting the last name 
    lblLastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 

    ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty); 
    lblNumber.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0); 
    if(ABPersonHasImageData(person)){ 
     imgPerson.image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)]; 
    } else { 
     imgPerson.image = [UIImage imageNamed:@"NotAvailable.png"]; 
    } 

    // remove the controller 
    [self dismissModalViewControllerAnimated:YES]; 

    return NO; 
} 
+0

感谢张建东但是我对给定函数的工作 - (BOOL)peoplePickerNavigationController:(的ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)个人财产:(ABPropertyID)属性标识符:(ABMultiValueIdentifier)标识符 而选择将其命名为显示的名称和电子邮件属性从那里选择任何一个属性应该存储的值 – user748001 2011-05-27 13:19:11

+0

如果您发现满意的答案,然后upvote和标记为正确.... – 2011-05-27 13:22:44

相关问题