当我开始在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