[英]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.