带导航控制器的UITabBarController在触摸时弹出子视图控制器

时间:2016-02-15 20:37:51

标签: swift uitabbarcontroller

我有带导航控件的UITabBarController。然后我将一个孩子VC推到导航控制器上,这个:

    let tabBarController = UITabBarController()
    let navController    = UINavigationController()
    let vc = Registration_VC()

    navController.addChildViewController(vc)
    tabBarController.addChildViewController(navController)
    self.presentViewController(tabBarController, animated: true, completion: nil)

这样可行。然后我将另一个VC(同一个)推送到导航控制器上,从注册_VC()'像这样:

        let vc = Registration_VC()
        self.navigationController?.pushViewController(vc, animated: true)

工作正常。然而,当我触摸TabBar上的任何地方时,当前的VC弹出。我不明白为什么。

1 个答案:

答案 0 :(得分:0)

对于 Swift 2 ,您必须使用以下代码来推送新的Viewcontroller:

let myViewControllerObejct = self.storyboard?.instantiateViewControllerWithIdentifier("ViewControllerIdentifier") as? myViewController
    self.navigationController?.pushViewController(viewControllerObject!, animated: true)

不需要addchildviewcontroller。我希望这有帮助