我想抓住联系人姓名的点击,并从那里获取联系信息。而不是单击联系人的信息并从那里单击一个字段。
我能够获取所需的所有数据,但只有在点击联系人后才能获取。这是我目前的代码:
-(IBAction)buttonPressed:(id)sender
{
ABPeoplePickerNavigationController *picker =[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
[self displayPerson:person];
[self dismissModalViewControllerAnimated:YES];
return YES;
}
-(void)displayPerson:(ABRecordRef)person
{
NSString *name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSLog(@"Name: %@", name);
NSString *phone = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
phone = (__bridge_transfer NSString *)
ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
} else {
phone = @"[None]";
}
NSLog(@"Phone: %@", phone);
}
- (void)peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:1)
只需在NO
中返回shouldContinueAfterSelectingPerson
。
根据docs:
返回值:
是,显示联系人并关闭选择器 不做任何事。
因此,通过返回NO
,您可以跳过显示步骤。无论如何,你自己解雇了拣货员。
答案 1 :(得分:0)
我正在使用:
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier;
但是,当我使用以下内容时,它的工作正常。这让我疯了。洛尔
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person;