2

I want to pull up the user's address book and use the new PeoplePicker controller to slice the results to show just those that match a certain term. I see that UIPeoplePickerNavigationController has a search bar and search view embedded in it. Looks like pretty standard stuff, I've just never used it before.

How would I get at that programmatically from a UIViewController subclass that has just presented the PeoplePicker modally?

Here's what I tried so far. Needless to say, it doesn't work.

ABPeoplePickerNavigationController *pick = [[ABPeoplePickerNavigationController alloc] init];
pick.searchDisplayController.searchBar.text = @"jim";
[self presentModalViewController:pick animated:YES];
[pick release];

EDIT: To be more clear, I want to bring up an ABPeoplePicker, but already "mid-search" with a search term that came from elsewhere in the app. If the user wants to cancel that search and run their own, that's fine, but I want to pre-load the searchviewcontroller with my own term first.

Dan Ray
  • 21,623
  • 6
  • 63
  • 87

2 Answers2

1

In case anyone's still wondering about this, I've reached a solution by manipulating the first responder status of the searchBar in the presentation completion block:

[self presentViewController:pick animated:YES completion:^{
    UISearchBar *bar = pick.visibleViewController.searchDisplayController.searchBar;
    [bar becomeFirstResponder];
    [bar setText:@"jim"];
    [bar resignFirstResponder];
}];

There's a momentary delay before it pulls up the search results, but this is the best way I've found to accomplish programmatic searching in an ABPeoplePickerNavigationController

flatpickles
  • 2,198
  • 2
  • 15
  • 21
0

check it whether you have declare ABPeoplePickerNavigationControllerDelegate or not.

and then run your app. I hope it will help you

Sivanathan
  • 1,213
  • 3
  • 13
  • 25