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

发布于 2024-08-22 10:48:25 字数 2137 浏览 4 评论 0原文

几周来我一直在寻找解决方案,我几乎绝望了。

问题很简单:

  • 通过 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 视图,但我不知道如何操作。

如果有人有任何想法那就太好了!

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

I'm near desperation as I search for a solution for weeks now.

The Problem is simple:

  • Via the ABPeoplePickerNavigationController (as a ModalView), a person should be selected.
  • Then only (e.g.) the Mail addresses should be shown and the user should select one.
  • After selection of a Mail address just the (e.g.) phone numbers should be shown and the user should select one.

The solution until the third aspect is well-known:

- (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;
}

The right approach seems to push a similar peoplePicker View on the NavigationController of the ModalView, but I don't know how.

If anyone had any idea it would be great!

If you want to see such a behavior in action you can have a look at the Amazon app: If you go through the first steps of an order you can select a shipping address exactly this way: From Contact List -> Select a Person -> Select an Address -> Select a Telephone number.
There, everything (seems to) take place in the modal view with just a navigation hierarchy with one more level than in the standard code shown above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

許願樹丅啲祈禱 2024-08-29 10:48:25

我想这可能就是您想要的:

- (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 的子类。

I guess this might be what you want:

- (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;
}

The idea is, to create another ABPersonViewController instance, and let your people picker to push it, since ABPeoplePickerNavigationController is a subclass of NSPeoplePickerNavigationController.

梦情居士 2024-08-29 10:48:25

在建议的答案中缺少一个版本

CFRelease(多);

如果没有这个释放,就会发生泄漏。或者至少根据 Xcode 中的构建和分析......

In the suggested answer there is a release missing

CFRelease(multi);

Without this release a leak will occur. Or at least according to the Build and Analyze in Xcode....

固执像三岁 2024-08-29 10:48:25

以下方法应返回 NO:

- (BOOL)peoplePickerNavigationController: 
  (ABPeoplePickerNavigationController*)peoplePicker 
  shouldContinueAfterSelectingPerson:(ABRecordRef)person 
{
  ...
  return NO;
}

这将允许调用您的下一个方法 (peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:)。

The following method should return NO:

- (BOOL)peoplePickerNavigationController: 
  (ABPeoplePickerNavigationController*)peoplePicker 
  shouldContinueAfterSelectingPerson:(ABRecordRef)person 
{
  ...
  return NO;
}

This will allow your next method be called (peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:).

左秋 2024-08-29 10:48:25

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

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

这只是一个简单的视图:

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

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

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

In my iPhone app Pastie, I took a different approach. alt text
(source: manicwave.com)

I use the peoplePicker to select the person and then open a contact (person) editor.

This is just a simple view:

Contact Name
Phone Number > defaults to first phone number
email Address > defaults to first email address

Each of phone number and email address bring up another view showing the list of phones or email addresses, with a check mark next to the currently selected one.

I use this view for initial setup of a contact as well as subsequent editing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文