iPhone ABPeoplePickerNavigationController – 如何从地址簿中选择一个人的两个不同多值属性的两个单个条目

我几个星期以前寻求解决方案,绝望绝望.

问题很简单:

>通过ABPeoplePickerNavigationController(作为ModalView),应该选择一个人.
>然后只显示(例如)邮件地址,用户应该选择一个.
>选择邮件地址后,应显示(例如)电话号码,用户应选择一个.

直到第三个方面的解决方案是众所周知的:

- (IBAction)importFromAddressBook 
{
    ABPeoplePickerNavigationController* picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker 
{
    [self dismissModalViewControllerAnimated:YES];
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker 
      shouldContinueAfterSelectingPerson:(ABRecordRef)person 
{
    [peoplePicker setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]]];
    return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier 
{
    //===PROBLEM=== Now I do have a mail address and I want to have a phone number right afterwards.

    //Something like this would be straightforward, but the view does not change this way:
    [peoplePicker setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]]];
    //Here misses the important code.


    //And only when I also got a phone number through this or a similar method I want to call:
    [peoplePicker dismissModalViewControllerAnimated:YES];

    //I do not want to start default behaviour with the mailaddress and/or phone number:
    return NO;
}

正确的方法似乎在ModalView的NavigationController上推出了一个类似的PeoplePicker View,但是我不知道如何.

如果有人有任何想法,那将是非常好的!

如果你想看到这样的行为,你可以看看亚马逊的应用程序:如果你通过订单的第一步,你可以选择这样一个送货地址:从联系人列表 – >选择一个人 – >选择地址 – >选择电话号码.
在那里,所有的东西(似乎)发生在模态视图中,只有一个导航层次结构比上面标准代码多一个.

最佳答案
我想这可能是你想要的:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person 
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier 
{

    ABPersonViewController *controller = [[ABPersonViewController alloc] init];
    controller.displayedPerson = person;
    controller.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
    controller.personViewDelegate = self;
    [peoplePicker pushViewController:controller animated:YES];
    [controller release];
    return NO;
}

- (BOOL)personViewController:(ABPersonViewController *)personViewController 
shouldPerformDefaultActionForPerson:(ABRecordRef)person 
                    property:(ABPropertyID)property
                  identifier:(ABMultiValueIdentifier)identifierForValue
{
    ABMutableMultiValueRef multi = ABRecordCopyValue(person, property);
    CFStringRef phone = ABMultiValueCopyValueAtIndex(multi, identifierForValue);
    NSLog(@"phone %@", (NSString *)phone);
    CFRelease(phone);

    ABPeoplePickerNavigationController *peoplePicker = (ABPeoplePickerNavigationController *)personViewController.navigationController;
    [peoplePicker dismissModalViewControllerAnimated:YES];
    return NO;
}

想法是创建另一个ABPersonViewController实例,让你的人选择者推送它,因为ABPeoplePickerNavigationController是NSPeoplePickerNavigationController的一个子类.

转载注明原文:iPhone ABPeoplePickerNavigationController – 如何从地址簿中选择一个人的两个不同多值属性的两个单个条目 - 代码日志