ggworean ggworean - 7 months ago 17
Swift Question

Navigation Back Bar not changing from previous view title

I've been trying to change the text for my back button. I've changed everything from the previous view's back button text, to the visible view's back button text, to setting the back button equal to a new button and changing its text. Alas, all I get is the text of the previous views title.

Answer

You cannot set the title of the back button item, but you can replace the back button directly.

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .Plain, target: nil, action: nil)

The trick is to set it on the pushing view controller, not on the one displaying the back button item.

You can set it in viewDidLoad of your pushing view controller. If you want to custom the back button according to the pushed view controllers, set it in prepareForSegue.