简体   繁体   English

当推入我的UITabBarController时,视图控制器隐藏的选项卡栏

[英]Tab bar hidden by view controller when pushed inside my UITabBarController

Note: And I tried to set the hidesBottomBarWhenPushed to false everywhere it was possible... 注意:并且我试图在可能的地方将hidesBottomBarWhenPushed设置为false。

Here is how I initialize my UITabBarController in my AppDelegate file: 这是我在AppDelegate文件中初始化UITabBarController的方法:

func initTabBarController()
{
    let myVC1 = MapVC()
    let myVC2 = MapVC()
    let myVC3 = MapVC()
    let myVC4 = MapVC()

    let controllers = [myVC1,myVC2,myVC3,myVC4]

    self.myTabBarController = UITabBarController()
    self.myTabBarController.viewControllers = controllers

    myVC1.tabBarItem = UITabBarItem(
        title: "Map",
        image: image1,
        selectedImage: image11)
    myVC2.tabBarItem = UITabBarItem(
        title: "Map",
        image: image2,
        selectedImage: image21)
    myVC3.tabBarItem = UITabBarItem(
        title: "Map",
        image: image3,
        selectedImage: image31)
    myVC4.tabBarItem = UITabBarItem(
        title: "Menu",
        image: image4,
        selectedImage: image41)

    self.tabNavigationController = UINavigationController(rootViewController: self.myTabBarController)

    self.tabNavigationController.navigationBar.translucent = false
}

Now Here is how I set the rootViewController of my main window: 现在,这是我设置主窗口的rootViewController的方法:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.initTabBarController()
        appDelegate.window!.rootViewController =    
appDelegate.tabNavigationController
        appDelegate.window!.makeKeyAndVisible()

And here is finally how I try to push a new view controller inside one of my ViewController (MapVC): 最后,这是我尝试在ViewController(MapVC)之一中推送新视图控制器的方法:

    let v = UIViewController()
    v.view.backgroundColor = UIColor.yellowColor()

    self.tabBarController?.navigationController?.pushViewController(v, animated: true)

When this code is executed, the Yellow view is well displayed, but the bottom tab bar is hidden. 执行此代码后,将很好地显示“黄色”视图,但底部的标签栏被隐藏。

And I'd like to still have my Tab Bar!!! 而且我想仍然拥有我的标签栏!!!

I tried to set the property hidesBottomBarWhenPushed to false to any object I can, unsuccessfully. 我试图将属性hidesBottomBarWhenPushed设置为false,但我无法将任何对象设置为成功。

Please help me!!! 请帮我!!!

Regards, Alx 问候,阿尔克斯

It looks like you have embedded your tabBarController in a NavigationController. 看起来您已经将tabBarController嵌入了NavigationController中。 That is probably why the tabs are hidden when a new ViewController is pushed on the stack. 这可能是在将新的ViewController推入堆栈时隐藏选项卡的原因。 Instead embed each of the tabBarController's ViewControllers inside their own NavigationController. 而是将每个tabBarController的ViewController嵌入其自己的NavigationController中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM