无法从 iOS8 中的联系人列表中找到 select 个人
Cannot select person from Contact List in iOS8
我知道之前有人问过这个问题,但这些线程中没有提到任何内容。许多人似乎有这个问题,因为委托是在 viewDidLoad 中设置的,但正如您从下面看到的那样,这不是我设置我的地方。 "Cancel" 操作确实起作用,因此委托起作用但不用于实际选择。
声明的协议:
@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:
委托方法。如果您想知道联系人何时被选中,请使用 peoplePickerNavigationController:didSelectPerson:
委托方法。
- (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];
}
我知道之前有人问过这个问题,但这些线程中没有提到任何内容。许多人似乎有这个问题,因为委托是在 viewDidLoad 中设置的,但正如您从下面看到的那样,这不是我设置我的地方。 "Cancel" 操作确实起作用,因此委托起作用但不用于实际选择。
声明的协议:
@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:
委托方法。如果您想知道联系人何时被选中,请使用 peoplePickerNavigationController:didSelectPerson:
委托方法。
- (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];
}