0

Presenting the people picker

ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.allowsActions = YES;
peoplePicker.allowsEditing = NO;
peoplePicker.peoplePickerDelegate = self;
[self presentViewController:peoplePicker animated:YES completion:nil];

Implementing the ABPeoplePickerNavigationControllerDelegate in iOS 7

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
  ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
  personViewController.displayedPerson = person;
  [peoplePicker pushViewController:personViewController animated:YES];
  return NO;
}

So far so good. The person view controller is presented as expected. iOS7 method returns a value - one could return NO in order to make sure the people picker remains open. In iOS8 the above delegate method was deprecated and new method must be implemented:

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person {
  ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
  personViewController.displayedPerson = person;
  [peoplePicker pushViewController:personViewController animated:YES];
}

The person view controller is pushed to the people picker but after a fraction of a second the people picker is dismissed (together with the person view controller).

Is there a way to prevent the people picker from dismissing on iOS8? Any other suggestions?

4

3 回答 3

0

presentViewController改用怎么样pushViewController...在Xcode 6中它说pushViewController已被弃用,我看到你正在尝试在iOS8中实现它所以试一试......像这样的一行:

[peoplePicker presentViewController: personViewController animated: YES completion: nil];
于 2014-10-31T14:32:35.220 回答
0
-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person
{ 
    [self dismissViewControllerAnimated:NO completion:^{
      ABPersonViewController *personController = [[ABPersonViewController alloc] init];

      [personController setDisplayedPerson:person];
      [personController setPersonViewDelegate:self];
      [personController setAllowsEditing:NO];
      personController.displayedProperties = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], nil];

      [self.navigationController pushViewController:personController animated:YES];
    }];
}
于 2014-10-31T13:59:17.943 回答
0

在 iOS8 中,初始化 ABPeoplePickerNavigationController 时需要添加如下代码,否则在选择联系人后 peoplePickerNavigationController 会立即关闭。

if(IOS8_OR_LATER){
    peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false]; }
于 2016-04-20T15:12:02.370 回答