uitableview – 在UISearchController文本字段中键入时,导航栏消失

当我开始在UISearchController.searchBar中输入时,我试图找出为什么我的整个导航栏消失了它正确加载并动画正确,但是当我开始输入时我失去了活动的NavBar.这是从viewDidLoad加载searchController的代码
UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

    searchResultsController.tableView.dataSource = self;
    searchResultsController.tableView.delegate = self;
    searchResultsController.tableView.backgroundColor = [UIColor redColor];    

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
    self.searchController.delegate = self;
    self.searchController.searchResultsUpdater = self;
    self.searchController.dimsBackgroundDuringPresentation = YES;
    self.searchController.hidesNavigationBarDuringPresentation = NO;

    [self.searchController.searchBar sizetoFit];

    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.definesPresentationContext = NO;

这是我开始输入后的结果:

注意表格视图是如何存在的,但它似乎占据了导航控制器的空间并向下延伸到第一部分标题中.有任何想法吗?

谢谢.

解决方法

您需要将definesPresentationContext设置为YES.从苹果例子:
// Search is Now just presenting a view controller. As such,normal view controller
// presentation semantics apply. Namely that presentation will walk up the view controller
// hierarchy until it finds the root view controller or one that defines a presentation context.

self.definesPresentationContext = YES

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...