我有一个带有导航栏 HIDDEN
的 UIViewController
,顶部有几个按钮,以及带有 UISearchController< 的
作为标题。
问题是:当我创建 UITableView
/UISearchController
时,我也有这一行:
self.definesPresentationContext = YES;
现在发生的事情是,当我使用 UISearchController
进行搜索并单击 UITableView
中的结果之一时,它会打开我的以下 UIViewController
(这正是它应该做的——下面的 UIViewController
也隐藏了导航栏)正确但它在 UIViewController< 的顶部显示了一个灰色的导航栏
,即使我将导航栏设置为隐藏。
现在当我设置:
self.definesPresentationContext = NO;
导航栏没有出现在下面的 View 中,而是 UISearchController 的 SearchBar
出现在下面的 UIViewController
中,与它在主视图中的位置相同 View Controller ,即使它显然不应该再存在了。
这是它应该看起来的样子(UIViewController 的顶部):
这是当 `self.definesPresentationContext = YES; 时发生的情况;
这就是当 `self.definesPresentationContext = NO; 时发生的情况;
我怎样才能回到第一种情况? 更新 这是一个重复此问题的示例项目: 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/