1

In my case, I'm making an app for real-time chat. I'm using large titles and search bar inside of my main view. However I wanted to add tabBar to my app navigationController and tabBar not working correct.

NOTE: I'm doing everything with code, please not tell me about storyboard.

Here is what supposed to be:

enter image description here

What is happening when I add tabBar:

enter image description here

AppDelegate.swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    UIApplication.shared.statusBarStyle = .lightContent

    FirebaseApp.configure()
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()

    window?.rootViewController = UINavigationController(rootViewController: TabBarController())

    return true
}

TabBarController.swift:

override func viewDidLoad() {
    super.viewDidLoad()

    let messagesController = UINavigationController(rootViewController: MessagesController())
    messagesController.tabBarItem.title = "Sohbetler"
    messagesController.tabBarItem.image = UIImage(named: "chats")

    viewControllers = [messagesController]
}
Ahmet Özrahat
  • 325
  • 2
  • 7
  • 18

2 Answers2

1

You put two navigation one for tabbar and second for controller hide one navigation bar and your problem will solve

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    UIApplication.shared.statusBarStyle = .lightContent

    FirebaseApp.configure()
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    let objNav = UINavigationController(rootViewController: TabBarController())
    objNav.isNavigationBarHidden = true
    window?.rootViewController = objNav

    return true
}
Chirag Shah
  • 3,034
  • 1
  • 30
  • 61
0

try the following line in your viewcontroller where you want to show the tabbar

self.tabBarController?.tabBar.isHidden = false