How to show / hide the search bar inside the navigation bar (iOS 8), as in the Apple Calendar app?

How to implement: I have a UIBarButtonItem with a search icon, after I click on it, I want to show the search bar in the navigation bar and the cancel button in the search bar, I want to show the navigation bar without searching and using buttons and headers, as in the iOS 7 calendar app.

+2
source share
1 answer

Customize the action for your search button to submit UISearchController. See Demo Search> Present Over Navigation Barin Apple UICatalog sample code :

- (IBAction)searchButtonClicked:(UIBarButtonItem *)sender {
    // Create the search results view controller and use it for the UISearchController.
    AAPLSearchResultsViewController *searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:AAPLSearchResultsViewControllerStoryboardIdentifier];

    // Create the search controller and make it perform the results updating.
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
    self.searchController.searchResultsUpdater = searchResultsController;
    self.searchController.hidesNavigationBarDuringPresentation = NO;

    // Present the view controller.
    [self presentViewController:self.searchController animated:YES completion:nil];
}
+8
source

All Articles