我需要以编程方式设置初始视图控制器(基于用户登录状态) 这是我的初始代码:
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
,我不知道如何在这里以编程方式设置它
有什么帮助吗?
答案 0 :(得分:1)
试试这个:
let tabBar = UITabBarController()
tabBar.viewControllers = [navigationController]
self.window!.rootViewController