[英]How do you activate a UISearchDisplayController when a button is clicked
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
. 我有这个
UISearchDisplayController
,到目前为止,只有当有人单击UISearchBar
时,它才能被激活(准备使用下拉的searchresulttableview
键入)。 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
. 查看
UISearchDisplayController
的文档。 There is an active
property and a setActive:animated:
method. 有一个
active
属性和一个setActive:animated:
方法。
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. 由于
UISearchBar
就像UITextField
一样扩展了UIResponder
,因此您可以简单地在搜索栏上调用becomeFirstResponder
使其成为焦点。
[button addTarget:self action:@selector(clickedSearchBar) forControlEvents:UIControlEventTouchUpInside];
- (void)clickedSearchBar {
[searchDisplayController.searchbar becomeFirstResponder];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.