2013-11-04 94 views
2

我有這個UISearchDisplayController,到目前爲止,它只能被激活(準備一個下拉searchresulttableview鍵入)當有人點擊UISearchBar。有沒有辦法讓按鈕來完成這項任務?我會很感激我收到的任何答案。如何激活一個UISearchDisplayController當按鈕被點擊

+1

有沒有這樣的事,作爲一個'UISearchBarViewController'。你的意思是'UISearchDisplayController'? – rmaddy

+0

是的,對不起。將編輯它。 –

回答

3

您在按鈕選擇器內嘗試過[searchDisplayController.searchbar becomeFirstResponder]嗎?

1

由於UISearchBar延伸UIResponder就像一個UITextField,你可以簡單地在搜索欄上調用becomeFirstResponder給它的焦點。

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

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

UISearchDisplayController的文檔。有一個active財產和一個setActive:animated:方法。

讓你的按鈕行動呼籲這一點:

[theSearchController setActive:YES animated:YES]; 
相關問題