ABPeoplePickerNavigationController实际执行

时间:2011-01-04 00:06:10

标签: iphone abpeoplepickerview

我的联系人列表在模拟器中完美显示。它需要电话号码并将其放在文本框中。所以我决定在我的iphone上尝试它,它实际上执行我点击的东西。它调用数字而不是将数字放在文本框中。继承人代码:

- (IBAction) adressBook: (id) sender {
 // creating the picker
 ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
 // place the delegate of the picker to the controll
 picker.peoplePickerDelegate = self;

 // showing the picker
 [self presentModalViewController:picker animated:YES];
 // releasing
 [picker release];
}


- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
    // assigning control back to the main controller
 [self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

 /* 
 ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
 num.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);


    //[self dismissModalViewControllerAnimated:YES];
 */
    return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
 NSLog(@"inbool");
 ABMultiValueRef phonePro = ABRecordCopyValue(person, property);
 int idx = ABMultiValueGetIndexForIdentifier(phonePro, identifier);
 num.text = (NSString*)ABMultiValueCopyValueAtIndex(phonePro, idx);


 [self dismissModalViewControllerAnimated:YES];
 /*
 ABMultiValueRef multi = ABRecordCopyValue(person, property);
 num.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, identifier);
 */


 return YES;
}

抱歉,如果格式不正确,那就是stackoverflow的新手。

1 个答案:

答案 0 :(得分:5)

您的peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:需要返回NO,以便手机不会执行默认操作。然后你自己关闭选择器。

-(BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController *) peoplePicker 
      shouldContinueAfterSelectingPerson: (ABRecordRef) person 
                                property: (ABPropertyID) property 
                              identifier: (ABMultiValueIdentifier) identifier
{
    NSLog(@"inbool"); 
    ABMultiValueRef phonePro = ABRecordCopyValue(person, property); 
    int idx = ABMultiValueGetIndexForIdentifier(phonePro, identifier); 
    num.text = (NSString)ABMultiValueCopyValueAtIndex(phonePro, idx);                             

    [peoplePicker dismissModalViewControllerAnimated: YES];

    return NO;  
}