我正在使用Apple提供的ABPeoplePickerNavigationController
课程来让用户选择联系人。
在此列表中,用户可以通过点按searchBar开始搜索。但是我希望用户不需要点击searchBar,因此我想在呈现视图控制器后自动进入搜索模式。
对于searchBar,您通常可以通过调用searchDisplayController setActive:YES animated:YES
来输入searchMode。这似乎无法使用ABPeoplePickerNavigationController
。
这就是我的尝试:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
[self presentViewController:picker animated:YES completion:^{
[picker.searchDisplayController.searchBar becomeFirstResponder];
[picker.searchDisplayController setActive:YES animated:YES];
}];
答案 0 :(得分:2)
由于ABPeoplePickerNavigationController
是一个navigationController,您看到的searchBar是该navigationController中topViewController
或visibleViewController
的一部分(实际上是ABMembersViewController
类通过AddressBookUI API公开。
要激活searchBar,您可以在完成块中执行以下操作:
[picker.visibleViewController.searchDisplayController.searchBar becomeFirstResponder];
[picker.visibleViewController.searchDisplayController setActive:YES animated:YES];