Navigating to a view (push) from a search results table (UISearchController) and keeping the search results in place

流过昼夜 提交于 2019-12-07 05:06:16

问题


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!


回答1:


I think there are 3 small changes you need to make.

  1. _searchController.hidesNavigationBarDuringPresentation = YES;
  2. [self presentViewController:_searchController animated:YES completion:nil];
  3. self.definesPresentationContext = YES; // in viewDidLoad of the viewController that presented the searchController


来源:https://stackoverflow.com/questions/41747551/navigating-to-a-view-push-from-a-search-results-table-uisearchcontroller-and

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