2

連絡先リストがシミュレーターに完全に表示されています。電話番号を取得し、テキスト ボックスに配置します。そこで、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 の新機能です。

4

1 に答える 1

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;  
}
于 2011-01-04T00:13:59.833 に答える