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 视图,但我不知道如何操作。
如果有人有任何想法那就太好了!
如果您想看到这种行为的实际效果,您可以查看亚马逊应用程序:如果您完成订单的第一步,您可以通过以下方式选择送货地址:从联系人列表 -> 。选择一个人 ->选择地址 ->选择一个电话号码。 在那里,一切(似乎)都发生在模态视图中,只有一个比上面显示的标准代码多一级的导航层次结构。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想这可能就是您想要的:
这个想法是,创建另一个 ABPersonViewController 实例,并让您的人员选择器推送它,因为 ABPeoplePickerNavigationController 是 NSPeoplePickerNavigationController 的子类。
I guess this might be what you want:
The idea is, to create another ABPersonViewController instance, and let your people picker to push it, since ABPeoplePickerNavigationController is a subclass of NSPeoplePickerNavigationController.
在建议的答案中缺少一个版本
如果没有这个释放,就会发生泄漏。或者至少根据 Xcode 中的构建和分析......
In the suggested answer there is a release missing
Without this release a leak will occur. Or at least according to the Build and Analyze in Xcode....
以下方法应返回 NO:
这将允许调用您的下一个方法 (peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:)。
The following method should return NO:
This will allow your next method be called (peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:).
在我的 iPhone 应用程序 Pastie 中,我采取了不同的方法。
(来源:manicwave.com)
我使用 peoplePicker选择人员,然后打开联系人(人员)编辑器。
这只是一个简单的视图:
联系人姓名
电话号码>默认为第一个电话号码
电子邮件地址>默认为第一个电子邮件地址
每个电话号码和电子邮件地址都会弹出另一个视图,显示电话或电子邮件地址列表,当前所选地址旁边有一个复选标记。
我使用此视图进行联系人的初始设置以及后续编辑。
In my iPhone app Pastie, I took a different approach.
(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.