[英]Cannot select person from Contact List in iOS8
我意识到这个问题已经被事先询问过了,但是在那些线程中没有提及。 许多人似乎都遇到了问题,因为委托是在viewDidLoad中设置的,但是正如您从下面看到的那样,这不是我设置我的地方。 “取消”操作确实起作用,因此委托起作用,但实际上不起作用。
协议声明:
@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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.