在app delegate中设置初始视图控制器时如何设置UITabBarController

时间:2015-02-03 09:33:51

标签: ios xcode swift uitabbarcontroller uistoryboard

我需要以编程方式设置初始视图控制器(基于用户登录状态) 这是我的初始代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainRootController = storyboard.instantiateViewControllerWithIdentifier("MainViewController") as UIViewController
if self.window != nil {

                let navigationController:UINavigationController = storyboard.instantiateInitialViewController() as UINavigationController
                navigationController.viewControllers = [mainRootController]

                self.window!.rootViewController = navigationController
}
return true

这会加载'MainViewController'。但我也错过了UITabBarController,我不知道如何在这里以编程方式设置它 有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

    let tabBar = UITabBarController()
    tabBar.viewControllers = [navigationController]
    self.window!.rootViewController