Eri-Sklii
Eri-Sklii

Reputation: 589

TabBarController TopBar Title

I am trying to add text to the top bar in my view controller. The view controller is connected to a TabBarController.

This is how i set my view controllers options: enter image description here

And this is the view controllers code:

override func viewDidAppear(animated: Bool) {
        println("viewDidAppear")
        self.tabBarItem.title = "Title"
        self.tabBarController?.selectedViewController?.title = "Title"
        self.tabBarController?.title = "Title"
    }

I have tried all those and none of them works..

And this is how it looks like in the storyboard: enter image description here

As you can see, what i want it to add text to the top of the view controller.

Upvotes: 1

Views: 480

Answers (3)

Ohmy
Ohmy

Reputation: 2221

When you have your Viewcontroller embedded in NavigationBar then you can do this in viewWillAppear

self.title = "My Title"

Upvotes: 0

Eri-Sklii
Eri-Sklii

Reputation: 589

I got something working now. I dragged in a "Navigation Bar", and now it works.

Upvotes: 0

Nakul Sharma
Nakul Sharma

Reputation: 610

You will have a UINavigationItem in your view controller in storyboard, If not you can embed in and You just have to set the title of of navigationItem either from storyboard or in viewDidLoad() or viewDidAppear()

override func viewDidAppear(animated: Bool) {
    println("viewDidAppear")
    self.navigationItem.title = "Title"
}

Upvotes: 3

Related Questions