在UISearchController文本字段中键入时,导航栏消失 [英] Navigation bar disappears when typing in UISearchController text field

查看:606
本文介绍了在UISearchController文本字段中键入时,导航栏消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图弄清楚当我开始在UISearchController.searchBar中输入时我的整个导航栏消失的原因它正确加载并动画正确,但是当我开始输入时我失去了活动的NavBar。这是从viewDidLoad加载searchController的代码:

I'm trying to figure out why my whole navigation bar disappears when I start typing in the UISearchController.searchBar It loads properly and animates properly, but I lose the active NavBar when I start typing. Here's the code to load the searchController from viewDidLoad:

    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;

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

And here's the result after I start typing:

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

Notice how the table view is there, but it appears to occupy the space of the nav controller and extend downwards into the first section heading. Any ideas?

谢谢。

推荐答案

你需要设置definePresentationContext是的。来自苹果示例:

You need to set definesPresentationContext to YES. From apples example:

// 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

这篇关于在UISearchController文本字段中键入时,导航栏消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆