Search code examples
iosuinavigationcontrollerswift2tabbarcontroller

Adding a navigation bar to tab view


Most of the tutorials that I came across are just showing a Navigation Controller and then a tableview controller, this works fine IF i am using only the tableview controller, but in mycase I am already using TabBar Controller and now I want to have a bar on top of the viewcontrollers , DOESN'T necessarily have to have a back button. But something that merges with the topbar (time, battery and carrier), right now I have this enter image description here

but when I run I get is this enter image description here

enter image description here

how can I fix this, do take note I am quite new and trying my best.

EDIT 1: Followed the comments advise, happy now, but no title. :(

enter image description here


Solution

  • Instead of wrapping your UITabBarController in a navigation controller, wrap every view controller inside a navigation controller and then add them (navigation controllers) to tab controller.

    Few tips:

    • self.tabBarController inside wrapped child UIViewControllers will give you the tab reference.
    • When you want to hide bottom bar when pushing next UIViewController, do nextViewController.hidesBottomBarWhenPushed = YES; and then push it on the self.navigationController will hide the bottom tab bar, handy when required.
    • You can use UITabBar and UITabBarItem appearance methods to customize the look of your tab bar from one place in the app.