[英]Storyboard - How to custom UITabbarItem with UITabbarController inside UINavigationController
[英]UITabbarController UITabbarItem does not appear when UINavigationController is embeded
如標題所示,如果我像這樣嵌入UINavigationController,則不會出現UITabbarItem:
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
}
如果刪除UINavigationController,它將正常工作,並且UITabbarItem可見。 如何嵌入UINavigationController並顯示UITabbarItem? (我不使用NIB或Storyboard,僅使用代碼)?
標簽欄項必須屬於您要添加到標簽欄控制器的視圖控制器-在本例中為導航控制器。 否則,它將嘗試從標題創建一個(不存在)。
您需要在導航控制器上而不是在其根視圖控制器上設置tabBarItem屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.