2

I am using the ABPeoplePickerNavigationController class provided by Apple to let the user pick a contact.

In this list the user can start searching by tapping into the searchBar. However I want that the user doesn't need to tap the searchBar and therefore I want to automatically enter into search mode after presenting the view controller.

For searchBar you can normally enter searchMode by calling searchDisplayController setActive:YES animated:YES. This However does not seem to work using the ABPeoplePickerNavigationController.

That is what I tried:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
[self presentViewController:picker animated:YES completion:^{
    [picker.searchDisplayController.searchBar becomeFirstResponder];
    [picker.searchDisplayController setActive:YES animated:YES];
}];
pre
  • 3,475
  • 2
  • 28
  • 43

1 Answers1

2

Since ABPeoplePickerNavigationController is a navigationController, the searchBar you see is part of the topViewController or visibleViewController in that navigationController (which is actually of the class ABMembersViewController that is not exposed by the AddressBookUI API).

To activate the searchBar, you can do the following in the completion block:

[picker.visibleViewController.searchDisplayController.searchBar becomeFirstResponder];
[picker.visibleViewController.searchDisplayController setActive:YES animated:YES];
Bram De Geyter
  • 1,088
  • 8
  • 15