2

In my UINavigationController I push three of UITableViewController. In my second UITableViewController I set in viewDidLoad:

self.navigationItem.title = "controller2"
self.navigationItem.backBarButtonItem?.title = "c2"

Then I do the following. Starting at UITableViewController one push UITableViewController two and push UITableViewController three on the UINavigationController. When I reach UITableViewController three the back button displays controller2 instead of c2.

I did the same setup on the first UITableViewController and when I reach UITableViewController two the back button shows the correct title.

Why does the back button shows the wrong title?

Michael
  • 32,527
  • 49
  • 210
  • 370

1 Answers1

2

As answered Here -

The title of the back button is either:

  1. The title of the previous view controller
  2. The name of the previous view controller's navigation item back button

If you are setting the back button for the current view controller's navigation item you are not setting the button that get's displayed in the current view. You are in fact setting the back button that will be used if you push another view controller from it.

Or You could init a new back button with title. Put this in the viewDidLoad() of view controller.

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "c2", style: UIBarButtonItemStyle.Bordered, target: nil, action: nil)
Community
  • 1
  • 1
Rahul Mane
  • 1,005
  • 18
  • 33