UISearchbar (UISearchResultsUpdating) with Segue does not dismiss

坚强是说给别人听的谎言 提交于 2020-01-03 16:51:14

问题


I have a problem with a UISearchBar. When I search some Text in combination with an UITableView, and ill click on one result Cell, the UISearchBar is still visible in the next UIViewController. the UISearchbar is still there (with the Keyword)

So after ill click on one result, ill get (in the next View Controller)but the searchbar and keyboard is still showing.

how can i dismiss the current UISearchController so that the search bar and keyboard do not show in the next UIViewController?

I have tried:

definesPresentationContext = true

i have tried to dismiss the presentingViewController.

Im doing all of this in the prepared for segue.

My thinking is that I have to dismiss the UISearchController...but how can I access it in preparedForSegue (in the searchResultsViewControllers - this is a tableViewController which is used to present the searchResults)


回答1:


You gotta use something like this, forget about the definesPresentationContext

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    searchController.active = false //This will dismiss the searchcontroller, use your own variable for searchController.
    //CALL THE SEGUE YOU WANT BELOW
}



回答2:


Try the following code to dismiss the search bar:

[yourSearchController.searchBar resignFirstResponder];


来源:https://stackoverflow.com/questions/32181330/uisearchbar-uisearchresultsupdating-with-segue-does-not-dismiss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!