复制UITabBarController

时间:2016-04-15 00:24:22

标签: ios swift uinavigationcontroller uitabbarcontroller

是否可以使用以下代码复制UITabBarController的行为?

我要做的是让“抽屉菜单”作为UITabBarController使用。每次按下任何菜单项时,该菜单项的选定VC将成为新的根VC,导航堆栈将重置,使VC成为堆栈中的第一个VC

dispatch_async(dispatch_get_main_queue(), { () -> Void in
        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let AccountVc = storyboard.instantiateViewControllerWithIdentifier("AccountVc")
        let navigationController = self.view.window?.rootViewController as! UINavigationController

        //Remove both login scene and menu scene
        self.presentingViewController!.presentingViewController!.dismissViewControllerAnimated(false) { () -> Void in
            navigationController.setViewControllers([AccountVc], animated: false)
        }
    })

上述代码有效,在这种情况下,它会将MenuVCloginVC一起删除,然后将导航设置AccountVC重置为新根。

有没有更好的方法呢?

0 个答案:

没有答案