我有一个搜索结果表(UISearchController
)呈现在导航堆栈上存在的视图上。我在视图中呈现搜索控制器和表格,如下所示:
_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];
这提出了一个UISearchBar
超过UINavigationBar
并且搜索表将按预期显示。当用户从表中选择搜索结果时,我想通过将其推送到导航堆栈来呈现选择的视图,同时搜索结果保持在原位。我现在的工作方式是,呈现搜索控制器的视图打开视图,但这需要关闭搜索控制器,因为search result view
显示在搜索结果表后面。
我怎样才能让搜索控制器推送search result view
到导航堆栈上,允许用户导航回搜索结果?
我希望它如何工作的一个示例可以在 iOS Mail 的日历应用程序中找到(当您搜索时)。
My navigationController
搜索结果控制器中的属性为零,因此我当前无法呈现search result view
从那里。
该项目同时使用 Objective-C 和 Swift,因此任何一个的答案都可以。任何帮助深表感谢!
我认为您需要做出 3 个小改变。
_searchController.hidesNavigationBarDuringPresentation = YES;
[self presentViewController:_searchController animated:YES completion:nil];
-
self.definesPresentationContext = YES;
// in viewDidLoad
呈现 searchController 的 viewController
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)