移动到下一个 UIViewController 时保留 UINavigationController 但隐藏 UITabBarController
Keep the UINavigationController while moving to next UIViewController but hide UITabBarController
我有一个 UITableViewController
嵌入在 UINavigationController
和 UITabBarController
中。
当我 select 一行时,我想在 UINavigationController
中打开我的 UIViewController
而不是在 UITabBarController
.
当我在 Interface Builder
中创建从单元格到 UIViewController
的 segue
时,我 select Show (eg. Push)
.
问题是它也保留了 UITabBarController
。
然后我尝试了其他类型的 segue,但其中 none 显示 UINavigationController
.
我考虑过在 viewDidLoad()
中添加 self.tabBarController?.tabBar.hidden = true
并覆盖 willMoveToParentViewController
:
override func willMoveToParentViewController(parent: UIViewController?) {
super.willMoveToParentViewController(parent)
if parent == nil {
self.tabBarController?.tabBar.hidden = false
}
}
它工作正常,除非我进行驱动转换(从边缘平移回到父视图控制器)。
正确的做法是什么?
UIViewController 有一个名为 hidesBottomBarWhenPushed
的 属性,它将完全满足您的需求。
只需设置 tableViewController.hidesBottomBarWhenPushed = true
就可以开始了!
编辑:如果您使用 Interface Builder 构建视图,实际上有一个复选框可以单击,因此您不必以编程方式设置它。
我有一个 UITableViewController
嵌入在 UINavigationController
和 UITabBarController
中。
当我 select 一行时,我想在 UINavigationController
中打开我的 UIViewController
而不是在 UITabBarController
.
当我在 Interface Builder
中创建从单元格到 UIViewController
的 segue
时,我 select Show (eg. Push)
.
问题是它也保留了 UITabBarController
。
然后我尝试了其他类型的 segue,但其中 none 显示 UINavigationController
.
我考虑过在 viewDidLoad()
中添加 self.tabBarController?.tabBar.hidden = true
并覆盖 willMoveToParentViewController
:
override func willMoveToParentViewController(parent: UIViewController?) {
super.willMoveToParentViewController(parent)
if parent == nil {
self.tabBarController?.tabBar.hidden = false
}
}
它工作正常,除非我进行驱动转换(从边缘平移回到父视图控制器)。
正确的做法是什么?
UIViewController 有一个名为 hidesBottomBarWhenPushed
的 属性,它将完全满足您的需求。
只需设置 tableViewController.hidesBottomBarWhenPushed = true
就可以开始了!
编辑:如果您使用 Interface Builder 构建视图,实际上有一个复选框可以单击,因此您不必以编程方式设置它。