Search code examples
iosswiftstoryboard

How to show the ViewController's title while using Tab Bar?


I'm trying develop a simple internet radio app for iOS in Swift with the storyboard editor. I'm new to the iOS-App-Development, so if use wrong words for my problem, I apologise.

I want to show the title of a view controller while using a Tab Bar for switching between the different ViewControllers.

In the past I tried to find an option for showing the title bar (?) in the attributes inspector and I also tried some code for setting the title programmatically. In storyboard mode it seems to work, but when I run the app, the bar is hidden.

I searched a long time for a solution, but actually I don't get it to work...


Solution

  • You have to Embed the ViewController in a UINavigationController

    You can either do that via Storyboard

    • Select The controller in the Storyboard
    • Select -> Editor (top menu bar)
    • Select Embed In -> UINavigationController

    Or if you are doing this programmatically you can

    let navigationController = UINavigationController(rootViewController: viewController)
    

    where viewController is your current visible controller.