当我开始在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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。