UINavigationBar - Set title programmatically?

Viewed 73113

I have a tab bar application with a different view on each tab. Each view has a UINavigationBar with title set on Interface Builder. I want to change the title based on a clause in the ViewDidLoad method, so if x { change the title }.

I have tried self.title = @"title", but this changes the title of the tab bar item itself.

So, how is this done?

11 Answers

Create IBOutlet of UINavigationBar

navigationBar.topItem.title = @"Title";

Hope this helps.

I achieved this way in Swift 5

override func viewDidLoad() {
    super.viewDidLoad()
    navigationItem.title = "Title"
}
Related