Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting notified when user presses "Search" on keyboard in UISearchDisplayController

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.

like image 387
Bryce Thomas Avatar asked Mar 16 '12 14:03

Bryce Thomas


2 Answers

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

like image 164
cxa Avatar answered Oct 25 '22 03:10

cxa


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

}

This also works with the keyboard search button.

like image 22
Gobot Avatar answered Oct 25 '22 02:10

Gobot