gpt4 book ai didi

ios - iOS8 无法从联系人列表中选择人员

转载 作者:行者123 更新时间:2023-11-29 01:53:28 25 4
gpt4 key购买 nike

我意识到之前有人问过这个问题,但这些线程中没有提到任何内容。许多人似乎有这个问题,因为委托(delegate)是在 viewDidLoad 中设置的,但正如您从下面看到的那样,这不是我设置我的地方。 “取消”操作确实起作用,因此代表起作用但不用于实际选择。

声明的协议(protocol):

@interface MyTrackDetailsTVC () <UITextFieldDelegate,UIImagePickerControllerDelegate,ABPeoplePickerNavigationControllerDelegate>

实例变量定义:

@property (strong, nonatomic) ABPeoplePickerNavigationController *picker;

从点击按钮开始的过程:

- (IBAction)importContactTapped:(UIButton *)sender
{
self.picker = [[ABPeoplePickerNavigationController alloc] init];

self.picker.peoplePickerDelegate = self;

[self presentViewController:self.picker animated:YES completion:nil];
}

取消方法工作得很好:

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker

{
[[peoplePicker presentingViewController]dismissViewControllerAnimated:YES completion:nil];
}

从未调用过选择方法(使用断点验证)。

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
NSString *fName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSData *imgData = (__bridge_transfer NSData *)ABPersonCopyImageData(person);

self.nameField.text = [NSString stringWithFormat:@"(%@ %@",fName,lName];
self.phoneField.text = lName;

self.imageView.image = [UIImage imageWithData:imgData];

[[peoplePicker presentingViewController]dismissViewControllerAnimated:YES completion:nil];
}

最佳答案

peoplePickerNavigationController:didSelectPerson:property:identifier: 委托(delegate)方法在选择联系人的特定属性时调用。如果您想知道联系人何时被选中,请使用 peoplePickerNavigationController:didSelectPerson: 委托(delegate)方法。

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
NSString *fName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSData *imgData = (__bridge_transfer NSData *)ABPersonCopyImageData(person);

self.nameField.text = [NSString stringWithFormat:@"(%@ %@",fName,lName];
self.phoneField.text = lName;

self.imageView.image = [UIImage imageWithData:imgData];

[[peoplePicker presentingViewController]dismissViewControllerAnimated:YES completion:nil];
}

关于ios - iOS8 无法从联系人列表中选择人员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31147195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com