Posts

Showing posts from December, 2013

iOS 7 UISearchBar Issue

Dear all, Transition into iOS 7 introduces a lot of adjustments. One such adjustment is the UISearchBar. If you try to set the UISearchBar to the NavigationBar inside a UIViewController, then it will not work correctly in iOS 7. The workaround for that is to use a UISearchDisplayController. Here are the steps. 1. Create your UISearchBar UISearchBar *newSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; newSearchBar.showsCancelButton=YES; newSearchBar.delegate=self; 2. Create a UISearchDisplayController and initialise with the UISearchBar & your ViewController UISearchDisplayController *searchDisplayController=[[UISearchDisplayController alloc] initWithSearchBar:newSearchBar contentsController:self]; 3. Set the datasource & delegates of the UISearchDisplayController searchDisplayController.delegate=self;//The delegate of UISearchDisplayController searchDisplayController.searchResultsDataSource=self;//The data source for the search res