导航栏上的SearchController在iOS11上不可见
在iOS 11发布之前,我在UITableViewController中添加了一个搜索栏。它隐藏在导航栏下,在用户向上滚动表格时可见。在iOS11上,调整contentOffset或tableview.bound不会正确隐藏搜索栏,有时它确实有效,有时它也会隐藏第一行。因此,我决定将搜索栏移动到导航栏。但是,由于某种原因,我在任何地方都看不到它。这是我在viewDidLoad的代码导航栏上的SearchController在iOS11上不可见,ios,objective-c,Ios,Objective C,在iOS 11发布之前,我在UITableViewController中添加了一个搜索栏。它隐藏在导航栏下,在用户向上滚动表格时可见。在iOS11上,调整contentOffset或tableview.bound不会正确隐藏搜索栏,有时它确实有效,有时它也会隐藏第一行。因此,我决定将搜索栏移动到导航栏。但是,由于某种原因,我在任何地方都看不到它。这是我在viewDidLoad的代码 YearTableViewController.m - (void)viewDidLoad { [super
YearTableViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
if (@available(iOS 11.0, *)) {
//iOS11 -> on navigation bar
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.barStyle = UISearchBarStyleDefault;
self.searchController.searchBar.showsCancelButton = NO;
[self.searchController.searchBar sizeToFit];
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.dimsBackgroundDuringPresentation = YES;
[self.navigationItem setSearchController:self.searchController];
[self.navigationController.navigationBar setPrefersLargeTitles:NO];
[self.navigationItem setLargeTitleDisplayMode:UINavigationItemLargeTitleDisplayModeNever];
self.definesPresentationContext = YES;
} else {
//iOS10 or previous -> on table view
UITableViewController *tableViewControllerForSearch = [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
tableViewControllerForSearch.tableView.dataSource = self;
tableViewControllerForSearch.tableView.delegate = self;
tableViewControllerForSearch.tableView.estimatedRowHeight = 40;
tableViewControllerForSearch.tableView.rowHeight = UITableViewAutomaticDimension;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:tableViewControllerForSearch];
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.tableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;
// No border between cells
tableViewControllerForSearch.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
}
编辑日期:2017/10/20
正如建议的那样,我已经重命名并简化了结构
我在故事板上有以下结构。
UINavigationController:初始视图控制器
YearPageViewController:内部有YearTableViewController
在iOS10上,它工作正常。在iOS 11上,我看不到搜索栏。
谢谢您的意见。添加怎么样
self.navigationItem.hidesSearchBarWhenScrolling = NO;
显然,搜索栏在默认情况下是隐藏的,只有在滚动时才能看到。添加搜索栏怎么样
self.navigationItem.hidesSearchBarWhenScrolling = NO;
显然,搜索栏在默认情况下是隐藏的,只有在滚动时才能看到。希望在iOS11上对您有所帮助
if #available(iOS 11.0, *) {
self.navigationItem.hidesSearchBarWhenScrolling = NO;
}
我知道为什么视图控制器是堆栈。在演示过程中,在DIMSBackground中设置“NO”标志
self.searchController.dimsBackgroundDuringPresentation = NO;
希望能对你在11号上有所帮助
if #available(iOS 11.0, *) {
self.navigationItem.hidesSearchBarWhenScrolling = NO;
}
我知道为什么视图控制器是堆栈。在演示过程中,在DIMSBackground中设置“NO”标志
self.searchController.dimsBackgroundDuringPresentation = NO;
为什么要在parentViewController上设置它?同时将UITableViewController命名为“searchController”令人困惑如果我这样做[self.navigationItem setSearchController:self.searchController],我将看不到搜索栏。找到解决方案了吗@Yoshitech为什么要在parentViewController上设置它?同时将UITableViewController命名为“searchController”令人困惑如果我这样做[self.navigationItem setSearchController:self.searchController],我将看不到搜索栏。找到解决方案了吗@yoshitechI将在我未来的更新中尝试此功能,但到目前为止它还不起作用。我可以创建一个具有类似结构(视图控制器堆栈)的示例应用程序,我怀疑是UIPageViewController作为UITableViewController的父级导致了这个问题。谢谢。更改代码上的此标志即可正常工作。searchController.dimsBackgroundDuringPresentation=NO;我将在以后的更新中尝试此功能,但到目前为止它不起作用。我可以创建一个具有类似结构(视图控制器堆栈)的示例应用程序,我怀疑是UIPageViewController作为UITableViewController的父级导致了这个问题。谢谢。更改代码上的此标志即可正常工作。searchController.dimsBackgroundDuringPresentation=NO;我将在以后的更新中尝试此功能,但到目前为止它不起作用。我可以创建一个具有类似结构(视图控制器堆栈)的示例应用程序,我怀疑是UIPageViewController作为UITableViewController的父级导致了这个问题。谢谢。我会在以后的更新中尝试这个,但到目前为止它还不起作用。我可以创建一个具有类似结构(视图控制器堆栈)的示例应用程序,我怀疑是UIPageViewController作为UITableViewController的父级导致了这个问题。谢谢