Getting notified when user presses “Search” on keyboard in UISearchDisplayController

时光怂恿深爱的人放手 提交于 2020-01-13 08:26:09

问题


I am using a UISearchDisplayController to let the user search through a list of buildings on a university campus. Sometimes, the user will know exactly what building they want, enter the building's number, and that building will then be the only building result showing in the UITableView. At the moment, if the user proceeds to hit "Search" on the keyboard, the keyboard animates off the screen and the user then has to make a second tap on the sole item in the UITableView to be sent to a point on a map showing the location of that building.

My question is, is there a way to be notified when the user hits the "Search" button on the keyboard inside a UISearchDisplayController, so that I can perform a check to see if there's only one result, and if so, take the user straight to that result, rather than requiring them to explicitly make the second tap? I've looked at the methods provided by the UISearchDisplayDelegate, but can't see anything relevant.


回答1:


UISearchDisplayController has a UISearchBar, you can set a delegate for search bar and implement -searchBarSearchButtonClicked:.




回答2:


- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {

}

This also works with the keyboard search button.



来源:https://stackoverflow.com/questions/9739500/getting-notified-when-user-presses-search-on-keyboard-in-uisearchdisplaycontro

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