iOS - UISearchController - definesPresentationContext 布局问题

标签 ios objective-c uitableview uisearchcontroller

我有一个带有导航栏 HIDDENUIViewController,顶部有几个按钮,以及带有 UISearchController< 的 UITableView/ 作为标题。 问题是:当我创建 UISearchController 时,我也有这一行:

    self.definesPresentationContext = YES;

现在发生的事情是,当我使用 UISearchController 进行搜索并单击 UITableView 中的结果之一时,它会打开我的以下 UIViewController(这正是它应该做的——下面的 UIViewController 也隐藏了导航栏)正确但它在 UIViewController< 的顶部显示了一个灰色的导航栏,即使我将导航栏设置为隐藏。

现在当我设置:

    self.definesPresentationContext = NO;

导航栏没有出现在下面的 View 中,而是 UISearchController 的 SearchBar 出现在下面的 UIViewController 中,与它在主视图中的位置相同 View Controller ,即使它显然不应该再存在了。

这是它应该看起来的样子(UIViewController 的顶部): enter image description here

这是当 `self.definesPresentationContext = YES; 时发生的情况;

enter image description here

这就是当 `self.definesPresentationContext = NO; 时发生的情况;

enter image description here

我怎样才能回到第一种情况? 更新 这是一个重复此问题的示例项目: http://www.filedropper.com/sampleprojectbugreport

最佳答案

它看起来确实像是 iOS 中的一个错误。如果您根本不打算显示导航栏,您可以子类化 UINavigationController 并覆盖 -setNavigationBarHidden:animated: 方法并对 hidden 进行硬编码 值:

-(void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated {
    [super setNavigationBarHidden:YES animated:animated];
}

我已经测试了这个解决方法,它阻止了导航栏的显示。

查看更新的示例项目:http://appsandwich.com/stackoverflow/navcontrollersubclass.zip

关于iOS - UISearchController - definesPresentationContext 布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35051957/

相关文章:

iOS:调整 UIWebView 的高度 - 奇怪的行为

objective-c - 如何使完成按钮在模式表中处于事件状态?

objective-c - 事件范围

ios - Swift UITableView 自定义单元格排序拖放?

ios - UITableView + 核心动画

ios - Telegram 官方应用程序代码中未下载图片

ios - 确定用户是否已启用应用程序的 Safari 内容拦截器扩展

ios - 如何将操作连接到以编程方式创建的 UIbutton

objective-c - NSDictionary 值替换而不是添加到 Plist

json - UITableView 不使用 SwiftyJSON 和 Alamofire 加载数据