I have a search results table (UISearchController
) that is presented on a view that exists on a navigation stack. I present the search controller and table on my view like this:
_searchResultsTableViewController = [[CalendarSearchResultsTableViewController alloc] init];
_searchResultsTableViewController.delegate = self;
_searchController = [[UISearchController alloc] initWithSearchResultsController:_searchResultsTableViewController];
_searchController.delegate = self;
_searchController.hidesNavigationBarDuringPresentation = NO;
_searchController.dimsBackgroundDuringPresentation = YES;
_searchController.obscuresBackgroundDuringPresentation = YES;
_searchController.active = YES;
_searchController.searchBar.delegate = self;
UIEdgeInsets adjustForTabbarInsets = UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.tabBarController.tabBar.frame), 0);
_searchResultsTableViewController.tableView.contentInset = adjustForTabbarInsets;
_searchResultsTableViewController.tableView.scrollIndicatorInsets = adjustForTabbarInsets;
[self.navigationController presentViewController:_searchController animated:YES completion:nil];
This presents a UISearchBar
over the UINavigationBar
and the search table appears as expected. When the user selects a search result from the table, I want to present a view for the selection by pushing it onto the navigation stack while the search results remain in place. The way I have it working now is that the view that presented the search controller opens the view, but this requires the search controller to be dismissed because the search result view
is presented behind the search results table.
How can I make it so that the search controller pushes the search result view
onto the navigation stack, allowing the user to navigate back to the search results?
An example of how I expect this to work can be found in the iOS Mail of Calendar app (when you search).
My navigationController
property in the search results controller is nil, so I cannot currently present the search result view
from there.
The project is in both Objective-C and Swift, so answers in either is fine. Any help is much appreciated!
I think there are 3 small changes you need to make.
_searchController.hidesNavigationBarDuringPresentation = YES;
[self presentViewController:_searchController animated:YES completion:nil];
self.definesPresentationContext = YES;
// in viewDidLoad
of the viewController that presented the searchControllerIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With