I have this UISearchDisplayController
and so far it can only be activated (ready to type with a drop down searchresulttableview
) when someone clicks the UISearchBar
. Is there a way to make a button do this task? I will appreciate any answer I receive.
您是否在按钮选择器中尝试过[searchDisplayController.searchbar becomeFirstResponder]
?
Look at the docs for UISearchDisplayController
. There is an active
property and a setActive:animated:
method.
Have your button action call this:
[theSearchController setActive:YES animated:YES];
Since UISearchBar
extends UIResponder
just like a UITextField
, you can simply call becomeFirstResponder
on the search bar to give it focus.
[button addTarget:self action:@selector(clickedSearchBar) forControlEvents:UIControlEventTouchUpInside];
- (void)clickedSearchBar {
[searchDisplayController.searchbar becomeFirstResponder];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.