Ios UISearchDisplayController无法隐藏导航栏
我正在处理一个带有搜索栏的视图。当搜索激活时,导航栏应设置动画(如Ios UISearchDisplayController无法隐藏导航栏,ios,uikit,uisearchdisplaycontroller,Ios,Uikit,Uisearchdisplaycontroller,我正在处理一个带有搜索栏的视图。当搜索激活时,导航栏应设置动画(如-[navigationController setNavigationBarHidden:animated:) 我已经使用UISearchDisplayController实现了这一点,除了无法隐藏导航栏之外,它做的大部分事情都是正确的。视图层次结构如下所示: UIWindow +-> IIViewDeckController +->UINavigationController +->UITable
-[navigationController setNavigationBarHidden:animated:
)
我已经使用UISearchDisplayController
实现了这一点,除了无法隐藏导航栏之外,它做的大部分事情都是正确的。视图层次结构如下所示:
UIWindow
+-> IIViewDeckController
+->UINavigationController
+->UITableViewController
- (void)viewDidLoad
{
UISearchBar *searchBar = [[UISearchBar alloc] init];
self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.tableView.tableHeaderView = searchBar;
}
UIWindow
+-> MMDrawerController
+->UINavigationController
+->UITableViewController
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
[self.searchContentsController.navigationController setNavigationBarHidden:visible animated:animated];
[super setActive:visible animated:animated];
}
我已经初始化了如下内容:
UIWindow
+-> IIViewDeckController
+->UINavigationController
+->UITableViewController
- (void)viewDidLoad
{
UISearchBar *searchBar = [[UISearchBar alloc] init];
self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.tableView.tableHeaderView = searchBar;
}
UIWindow
+-> MMDrawerController
+->UINavigationController
+->UITableViewController
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
[self.searchContentsController.navigationController setNavigationBarHidden:visible animated:animated];
[super setActive:visible animated:animated];
}
我还尝试使用不同的抽屉控制器来查看问题是否出在IIViewDeckController中,如下所示:
UIWindow
+-> IIViewDeckController
+->UINavigationController
+->UITableViewController
- (void)viewDidLoad
{
UISearchBar *searchBar = [[UISearchBar alloc] init];
self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.tableView.tableHeaderView = searchBar;
}
UIWindow
+-> MMDrawerController
+->UINavigationController
+->UITableViewController
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
[self.searchContentsController.navigationController setNavigationBarHidden:visible animated:animated];
[super setActive:visible animated:animated];
}
通常,UISearchDisplayController
应该调用-[UINavigationController setNavigationBarHidden:animated:
中的某个地方的-[UISearchDisplayController setActive:animated:
。我甚至尝试过创建一个派生自UISearchDisplayController
的类并重载-[UISearchDisplayController setActive:animated:
并手动隐藏导航栏,如下所示:
UIWindow
+-> IIViewDeckController
+->UINavigationController
+->UITableViewController
- (void)viewDidLoad
{
UISearchBar *searchBar = [[UISearchBar alloc] init];
self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.tableView.tableHeaderView = searchBar;
}
UIWindow
+-> MMDrawerController
+->UINavigationController
+->UITableViewController
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
[self.searchContentsController.navigationController setNavigationBarHidden:visible animated:animated];
[super setActive:visible animated:animated];
}
为清晰起见,更新:这段代码确实像预期的那样隐藏了导航栏,但它没有清除位于搜索栏北部的视图,我最后看到另一个视图位于状态栏顶部(这有点道理,因为在通过-[UISearchDisplayController setActive:animated:]进行调试时
我发现它在隐藏导航栏时使用了一些私有API来清除刷新控制器。我想
出于某种原因,导航栏没有隐藏,我一直在努力找出原因
什么会导致这种行为
更新#2
看起来我错过了层次结构中的一个视图,在某种程度上,它似乎是罪魁祸首(仍然不确定具体以何种方式)。下面是:
UIWindow
+-> MMDrawerController
+-> UINavigationController
+-> UITabBarController
+-> UITableViewController
看起来问题出在
UITabBarController
上,我早就知道了,因为这里已经提到了它(),文档中也提到了它:
使用选项卡栏控制器的应用程序也可以使用导航
一个或多个选项卡中的控制器。当组合这两种类型的
在同一用户界面(选项卡栏控制器)中查看控制器
始终充当导航控制器的包装器
答案是,在我看来,视图层次结构需要改变,这样就没有UITabBarController(因为使用一个UITabBarController将要求它是根控制器,这将强制重新设计应用程序)。看起来最可行的替代方案是。你使用iOS 7吗?如果你使用,可能是解决方案。为什么在
UITabBarController
内部有UITabBarController
会成为问题?@fumoboy007不是。问题在于UINavBarController内部有一个UITabBarController
最近这个问题有什么解决办法吗?