1

我正在尝试点击联系人姓名,并从那里获取联系信息。而不是单击联系人的信息并从那里单击一个字段。

我能够获取所有需要的数据,但只有在点击联系人之后。这是我当前的代码:

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

2 回答 2

1

只需返回NOshouldContinueAfterSelectingPerson

根据文档

返回值:
YES 显示联系人并关闭选择器。
NO 什么都不做。

因此,通过返回NO,您可以跳过显示步骤。无论如何,您自己都在解雇选择器。

于 2012-02-26T01:37:48.953 回答
0

我正在使用:

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier;

但是,当我使用以下内容时,它工作得很好。这让我发疯了。哈哈

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person;
于 2012-02-27T00:25:51.427 回答