iPhone ABPeoplePickerNavigationController - 如何从Addressbook中选择一个人的两个不同多值属性的两个单个条目

And*_*dré 11 iphone objective-c contacts addressbook peoplepicker

我几乎要绝望了,因为我现在正在寻找解决方案.

问题很简单:

  • 通过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;
}
Run Code Online (Sandbox Code Playgroud)

正确的方法似乎在ModalView的NavigationController上推送类似的peoplePicker View,但我不知道如何.

如果有人知道它会很棒!

如果您想看到这样的行为,您可以查看亚马逊应用程序:如果您完成订单的第一步,您可以按照以下方式选择送货地址:从联系人列表 - >选择一个人 - >选择地址 - >选择电话号码.在那里,一切(似乎)都发生在模态视图中,只有一个导航层次结构,其级别比上面显示的标准代码多一个级别.

zon*_*ble 15

我猜这可能是你想要的:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

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


小智 1

在我的 iPhone 应用程序 Pastie 中,我采取了不同的方法。替代文本
(来源:manicwave.com

我使用 peoplePicker 选择人员,然后打开联系人(人员)编辑器。

这只是一个简单的视图:

联系人姓名 电话号码 > 默认为第一个电话号码 电子邮件地址 > 默认为第一个电子邮件地址

每个电话号码和电子邮件地址都会弹出另一个视图,显示电话或电子邮件地址列表,当前所选地址旁边有一个复选标记。

我使用此视图进行联系人的初始设置以及后续编辑。