我几乎要绝望了几周,因为我现在正在寻找解决方案。
问题很简单:
直到第三方面的解决方案众所周知:
- (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,但我不知道如何。
如果有人知道它会很棒!
如果您希望看到这样的行为,您可以查看亚马逊应用:如果您完成订单的第一步,您可以通过以下方式选择送货地址:来自联系人列表 - >选择一个人 - >选择地址 - >选择一个电话号码。 在那里,一切(似乎)都发生在模态视图中,只有一个导航层次结构,其级别比上面显示的标准代码多一个。
答案 0 :(得分: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;
}
这个想法是,创建另一个ABPersonViewController实例,让你的人选择器推送它,因为ABPeoplePickerNavigationController是NSPeoplePickerNavigationController的子类。
答案 1 :(得分:1)
在我的iPhone应用程序Pastie中,我采取了不同的方法。 alt text http://manicwave.com/images/pastie/contactdetails.png
我使用peoplePicker选择人物,然后打开联系人(人物)编辑器。
这只是一个简单的观点:
联系人姓名 电话号码>默认为第一个电话号码 电子邮件地址>默认为第一个电子邮件地址
每个电话号码和电子邮件地址都会显示另一个显示电话或电子邮件地址列表的视图,并在当前选定的一个旁边显示复选标记。
我使用此视图进行联系人的初始设置以及后续编辑。
答案 2 :(得分:1)
在建议的答案中,缺少一个版本
CFRelease(多);
如果没有此版本,则会发生泄漏。或者至少根据Xcode中的Build and Analyze ....
答案 3 :(得分:1)
以下方法应返回NO:
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController*)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
...
return NO;
}
这将允许调用你的下一个方法(peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier :)。