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 cl
Use
self.navigationItem.title = @"the title";
as setting navBar.topItem.title
will not work in all circumstances.
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"
}
You can also just set the title in the ViewDidLoad under your ViewController or TableViewController using
_title = @"Title";
or
self.title = @"Title";
I used the following:
self.navigationController.navigationBar.topItem.title = @"Title";
However, I also had to call it in a dispatch block as it wouldn't change the title when called within the viewDidLoad w/o it.
Note that in order for the title to show up AT ALL the Navigation Controller's delegate MUST be set to the navigation bar itself or the title will NEVER show!