简体   繁体   English

无法在iOS8的联系人列表中选择人

[英]Cannot select person from Contact List in iOS8

I realize this question has been asked prior but nothing mentioned in those threads worked. 我意识到这个问题已经被事先询问过了,但是在那些线程中没有提及。 Many seemed to have the issue because the delegate was set in viewDidLoad but as you can see from the below, that is not where I am setting mine. 许多人似乎都遇到了问题,因为委托是在viewDidLoad中设置的,但是正如您从下面看到的那样,这不是我设置我的地方。 The "Cancel" operation DOES work so the delegate works but not for actually selecting. “取消”操作确实起作用,因此委托起作用,但实际上不起作用。

Protocol declared: 协议声明:

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

Instance variable defined: 实例变量的定义:

@property (strong, nonatomic) ABPeoplePickerNavigationController *picker;

Process initiated from a button tap: 从按钮点击开始的过程:

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

    self.picker.peoplePickerDelegate = self;

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

Cancel method works just fine: 取消方法效果很好:

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker

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

Selection method never called (verified with break points). 选择方法从未调用过(已通过断点验证)。

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

The peoplePickerNavigationController:didSelectPerson:property:identifier: delegate method is called when a specific property on a contact is selected. 选择联系人的特定属性时,将调用peoplePickerNavigationController:didSelectPerson:property:identifier:委托方法。 If you want to know when a contact is selected, use the peoplePickerNavigationController:didSelectPerson: delegate method. 如果您想知道何时选择联系人,请使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM