简体   繁体   中英

how to show the searchResultsController of UISearchController when the searchBar is pressed

在这里输入图像描述,我必须输入一些单词以显示searchResultsController,但是我想做的就是在searchBar处于活动状态时立即显示searchResultsController。我该怎么做?

The only way I know how to do this is by implementing the UISearchBarDelegate and then implement searchBarShouldBeginEditing. What you can do then is something like this:

func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
    self.tabBarController?.selectedIndex = 1
    return false
}

Unless the search view controller isn't situated in the tabbar, then you can just tell the navigationController to slide the searchResultsController into view. In the searchResultsController you can tell the searchbar to start editing with:

searchbar.becomeFirstResponder()

Just make sure to be aware from where the user comes from because I'd imagine it might be annoying if it would get called everytime viewDidAppear gets triggered.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM