从搜索结果 table (UISearchController) 导航到视图(推送)并将搜索结果保持在原位
Navigating to a view (push) from a search results table (UISearchController) and keeping the search results in place
我有一个搜索结果 table (UISearchController
),它显示在导航堆栈中存在的视图上。我在我的视图中展示了搜索控制器和 table:
_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];
这会在 UINavigationBar
上显示一个 UISearchBar
,并且搜索 table 会按预期出现。当用户从 table 中选择一个搜索结果时,我想在搜索结果保留在原处的同时,通过将其推送到导航堆栈来呈现所选内容的视图。我现在的工作方式是呈现搜索控制器的视图打开视图,但这需要关闭搜索控制器,因为 search result view
显示在搜索结果 table 后面。
我怎样才能让搜索控制器将 search result view
推送到导航堆栈,允许用户导航回搜索结果?
可以在 iOS 日历邮件应用程序(当您搜索时)中找到我希望它如何工作的示例。
我的 navigationController
属性 在搜索结果控制器中为零,因此我目前无法从那里显示 search result view
。
该项目在 Objective-C 和 Swift 中,所以在任何一个中的答案都可以。非常感谢任何帮助!
我认为您需要进行 3 处小改动。
_searchController.hidesNavigationBarDuringPresentation = YES;
[self presentViewController:_searchController animated:YES completion:nil];
self.definesPresentationContext = YES;
// 在呈现 searchController 的 viewController 的 viewDidLoad
中
我有一个搜索结果 table (UISearchController
),它显示在导航堆栈中存在的视图上。我在我的视图中展示了搜索控制器和 table:
_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];
这会在 UINavigationBar
上显示一个 UISearchBar
,并且搜索 table 会按预期出现。当用户从 table 中选择一个搜索结果时,我想在搜索结果保留在原处的同时,通过将其推送到导航堆栈来呈现所选内容的视图。我现在的工作方式是呈现搜索控制器的视图打开视图,但这需要关闭搜索控制器,因为 search result view
显示在搜索结果 table 后面。
我怎样才能让搜索控制器将 search result view
推送到导航堆栈,允许用户导航回搜索结果?
可以在 iOS 日历邮件应用程序(当您搜索时)中找到我希望它如何工作的示例。
我的 navigationController
属性 在搜索结果控制器中为零,因此我目前无法从那里显示 search result view
。
该项目在 Objective-C 和 Swift 中,所以在任何一个中的答案都可以。非常感谢任何帮助!
我认为您需要进行 3 处小改动。
_searchController.hidesNavigationBarDuringPresentation = YES;
[self presentViewController:_searchController animated:YES completion:nil];
self.definesPresentationContext = YES;
// 在呈现 searchController 的 viewController 的
viewDidLoad
中