Reputation: 21893
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.
Upvotes: 2
Views: 1021
Reputation: 2296
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
Upvotes: 1
Reputation: 1213
check it whether you have declare ABPeoplePickerNavigationControllerDelegate or not.
and then run your app. I hope it will help you
Upvotes: 0