[英]How to fix “Unexpectedly found nil” in app Delegate when setting UITabBarController as root view controller
[英]How to set UITabBarController when setting initial view controller in app delegate
我需要以編程方式設置初始視圖控制器(基於用戶登錄狀態)。
這是我的初始代碼:
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
,我不知道如何在這里以編程方式設置它。
有什么幫助嗎?
試試這個:
let tabBar = UITabBarController()
tabBar.viewControllers = [navigationController]
self.window!.rootViewController
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.