Ios 单击按钮时如何激活UISearchDisplayController

Ios 单击按钮时如何激活UISearchDisplayController,ios,iphone,objective-c,uibutton,uisearchbar,Ios,Iphone,Objective C,Uibutton,Uisearchbar,我有这个UISearchDisplayController,到目前为止,只有当有人单击UISearchBar时,它才能被激活(准备使用下拉菜单searchresultableview)。有没有办法让按钮执行此任务?我将非常感谢您的回答。您是否尝试过将[searchDisplayController.searchbar becomeFirstResponder]放在按钮选择器中?因为UISearchBar扩展了UIResponder就像UITextField一样,您只需在搜索栏上调用becomeF

我有这个
UISearchDisplayController
,到目前为止,只有当有人单击
UISearchBar
时,它才能被激活(准备使用下拉菜单
searchresultableview
)。有没有办法让按钮执行此任务?我将非常感谢您的回答。

您是否尝试过将
[searchDisplayController.searchbar becomeFirstResponder]
放在按钮选择器中?

因为
UISearchBar
扩展了
UIResponder
就像
UITextField
一样,您只需在搜索栏上调用
becomeFirstResponder
,即可获得焦点

[button addTarget:self action:@selector(clickedSearchBar) forControlEvents:UIControlEventTouchUpInside];

- (void)clickedSearchBar {
    [searchDisplayController.searchbar becomeFirstResponder];
}

查看
UISearchDisplayController
的文档。有一个
active
属性和一个
setActive:animated:
方法

让您的按钮操作调用以下命令:

[theSearchController setActive:YES animated:YES];

没有所谓的
UISearchBarViewController
。你是说
UISearchDisplayController
?是的,很抱歉。我将编辑它。