You should probably write your own PeoplePickerViewController since you will never have enough control over the default Apple controller.
In any case, regarding your current problem, here is what you need to do:
Declare three new properties (use appropriate declarations based on if you use ARC or not - I do not assume ARC)
@property (nonatomic, assign) ABPeoplePickerNavigationController *peoplePicker; @property (nonatomic, assign) UIViewController *peoplePickerRootViewController; @property (nonatomic, copy) NSString *currentSearchString;
Now that you are showing the people picker, add the following lines:
// save people picker when displaying self.peoplePicker = [[[ABPeoplePickerNavigationController alloc] init] autorelease]; // save it top view controller self.peoplePickerRootViewController = self.peoplePicker.topViewController; // need to see when view controller is shown/hidden - viewWillAppear:/viewWillDisappear: won't work so don't bother with it. self.peoplePicker.delegate = self;
Now we will save the search bar just before clicking on the user icon:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { self.currentSearchString = nil; if ([self.peoplePickerRootViewController.searchDisplayController isActive]) { self.currentSearchString = self.peoplePickerRootViewController.searchDisplayController.searchBar.text; }
Obviously, implement the UINavigationControllerDelegate in this class. When the root view returns to view, we will force the search results to be displayed. Here's the implementation for navigationController:willShowViewController:animated:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if (navigationController == self.peoplePicker) { if (viewController == self.peoplePickerRootViewController) { if (self.currentSearchString) { [self.peoplePickerRootViewController.searchDisplayController setActive: YES]; self.peoplePickerRootViewController.searchDisplayController.searchBar.text = self.currentSearchString; [self.peoplePickerRootViewController.searchDisplayController.searchBar becomeFirstResponder]; } self.currentSearchString = nil; } } }
Remember to release currentSearchString in dealloc if you are not using ARC.
A little caution. When choosing a person, when ABPeoplePickerNavigationController tries to hide the presentation of the search results, a slight flicker appears.