iOS - UISearchController - definesPresentationContext布局问题

时间:2016-01-28 02:44:43

标签: ios objective-c uitableview uisearchcontroller

我有UIViewController个导航栏HIDDEN,顶部有几个按钮,UITableView标题为UISearchController。 问题在于:当我创建UISearchController时,我也有这一行:

    self.definesPresentationContext = YES;

现在发生的情况是,当我使用UISearchController进行搜索,然后点击UITableView中的某个结果时,会打开我的关注UIViewController(这正是它的本质)应该这样做 - 并且以下UIViewController也隐藏了导航栏)但它在UIViewController顶部显示了一个灰色的导航栏,即使我设置了导航栏隐藏的。

现在我设置:

    self.definesPresentationContext = NO;

导航栏不会显示在以下视图中,而是显示在UISearchController's SearchBar以下UIViewController与主视图控制器中相同的位置,即使它&# 39;显然不应该再呆在那里了。

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

当self.definesPresentationContext = YES;

时会发生这种情况

enter image description here

这就是`self.definesPresentationContext = NO;

时会发生的事情

enter image description here

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

1 个答案:

答案 0 :(得分:2)

它看起来像iOS中的错误。如果您不打算完全显示导航栏,则可以继承UINavigationController并覆盖-setNavigationBarHidden:animated:方法并对hidden值进行硬编码:

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

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

请参阅更新的示例项目:http://appsandwich.com/stackoverflow/navcontrollersubclass.zip