2014-11-24 19 views
0

正如標題所說,請問UITabbarItem沒有,如果我在一個UINavigationController嵌入像這樣出現:的UITabBarController UITabbarItem不會出現時的UINavigationController被包埋

lazy var tabBarViewController: UITabBarController = { 
     let tBarViewController = UITabBarController() 

     let firstViewController = ViewController() 
     firstViewController.tabBarItem.title = "Home" 
     tBarViewController.viewControllers = [UINavigationController(rootViewController: firstViewController)] 

     return tBarViewController 
     }() 

    lazy var window: UIWindow = { 
     let win = UIWindow(frame: UIScreen.mainScreen().bounds) 
     win.backgroundColor = UIColor.whiteColor() 
     win.rootViewController = self.tabBarViewController 
     return win 
     }() 


    func customizeAppereance() { 

     UINavigationBar.appearance().barTintColor = UIColor.themeColor() 
     UITabBar.appearance().barTintColor = UIColor.themeColor() 

    } 


    func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool { 

     customizeAppereance() 

     UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: .Fade) 
     window.makeKeyAndVisible() 

     return true 
    } 

enter image description here

如果我刪除的UINavigationController它的工作原理並且UITabbarItem可見。 如何嵌入UINavigationController並讓UITabbarItem出現? (我不使用NIB或Storyboard,只是代碼)?

回答

0

標籤欄項必須屬於您要添加到標籤欄控制器的視圖控制器 - 在本例中爲導航控制器。否則,它會嘗試從標題創建一個(不存在)。

您需要在導航控制器上設置tabBarItem屬性,而不是其根視圖控制器。

相關問題