ABPeoplePickerNavigationController 实际执行

发布于 2024-10-10 20:01:47 字数 1770 浏览 3 评论 0原文

我的联系人列表在模拟器中完美显示。它获取电话号码并将其放入文本框中。所以我决定在我的 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 的新手。

i have the contact list showing up perfectly in the simulator. it takes the phone number and places it in the text box. so i decided to try it on my iphone and it actually executes the thing i tap on. it calls the number instead of putting the number ito the textbox. heres the code:

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

and sorry if not formatted correctly, new to stackoverflow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2024-10-17 20:01:47

您的 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;  
}

Your peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier: needs to return NO so that the phone does not perform it's default action. You then close the picker yourself.

-(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;  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文