现在我正在使用<AddressBookUI/AddressBookUI.h>
它正常工作,打开地址视图控制器,点击一个联系人后进入详细视图,我可以点击任何属性来选择并获取信息。
下面是我现在正在使用的代码:
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
[self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier]; }
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
[picker dismissModalViewControllerAnimated:YES]; }
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
ABMutableMultiValueRef multi = ABRecordCopyValue(person, property);
CFStringRef phone1 = ABMultiValueCopyValueAtIndex(multi, identifier);
NSLog(@"phone %@", (__bridge NSString *)phone1);
CFRelease(phone1);
ABMultiValueRef fnameProperty = ABRecordCopyValue(person, kABPersonFirstNameProperty);
ABMultiValueRef lnameProperty = ABRecordCopyValue(person, kABPersonLastNameProperty);
ABMultiValueRef phoneProperty = ABRecordCopyValue(person, kABPersonPhoneProperty);
ABMultiValueRef emailProperty = ABRecordCopyValue(person, kABPersonEmailProperty);
NSArray *emailArray = (__bridge NSArray *)ABMultiValueCopyArrayOfAllValues(emailProperty);
NSArray *phoneArray = (__bridge NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);
NSString *name,*phone,*email;
phone = [[NSString alloc]init];
email = [[NSString alloc]init];
name = [[NSString alloc]init];
if (fnameProperty != nil) {
name = [NSString stringWithFormat:@"%@", fnameProperty];
}
if (lnameProperty != nil) {
name = [name stringByAppendingString:[NSString stringWithFormat:@" %@", lnameProperty]];
}
if ([phoneArray count] > 0) {
if ([phoneArray count] > 1) {
for (int i = 0; i < [phoneArray count]; i++) {
phone = [phone stringByAppendingString:[NSString stringWithFormat:@"%@,", [phoneArray objectAtIndex:i]]];
}
}else {
phone = [NSString stringWithFormat:@"%@", [phoneArray objectAtIndex:0]];
}
}
if ([emailArray count] > 0) {
if ([emailArray count] > 1) {
for (int i = 0; i < [emailArray count]; i++) {
email = [email stringByAppendingString:[NSString stringWithFormat:@"%@\n", [emailArray objectAtIndex:i]]];
}
}else {
email = [NSString stringWithFormat:@"%@", [emailArray objectAtIndex:0]];
}
}
//----setting txt field values
NSArray *f_name = [name componentsSeparatedByString:@" "];
if(f_name.count>1)
{
txtFirstname.text = [f_name objectAtIndex:0];
txtLastname.text = [f_name objectAtIndex:1];
}else{
txtFirstname.text = [f_name objectAtIndex:0];
}
NSArray *only_1_no = [phone componentsSeparatedByString:@","];
NSString *str = [only_1_no objectAtIndex:identifier];
NSCharacterSet *unwantedStr = [NSCharacterSet characterSetWithCharactersInString:@"+() -"];
str = [[str componentsSeparatedByCharactersInSet: unwantedStr] componentsJoinedByString: @""];
NSArray *ar = [email componentsSeparatedByString:@"\n"];
NSMutableString *abcd = [[NSMutableString alloc]init];
for (int i = 0; i<str.length; i++)
{
NSString *abc = [NSString stringWithFormat:@"%C",[phone characterAtIndex:i]];
if(i==0){
abcd =[NSMutableString stringWithFormat:@"%@",abc];
}else{
abcd = [NSMutableString stringWithFormat:@"%@%@",abcd,abc];
}
[self showmaskonnumber:abcd];
}
txtPhoneno.text = str;
txtEmail.text = [ar objectAtIndex:0];
ABPeoplePickerNavigationController *peoplePicker1 = (ABPeoplePickerNavigationController *)peoplePicker.navigationController;
[peoplePicker1 dismissModalViewControllerAnimated:YES];
[txtEmail becomeFirstResponder];
return YES;
}
我的问题是:我应该对此代码进行哪些更改,因此当我在地址列表视图中选择联系人时,选择会返回联系人及其所有信息而不显示其详细信息?
答案 0 :(得分:0)
我通过使用此委托方法解决了我的问题
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person;
{ [self selectedPerson:person]; }