Search code examples
iosuiviewcontrolleruinavigationcontroller

Setting navigationItem title delay issues


When pushing a controller to the navigation stack i execute:

self.navigationItem.title = "";

As i dont want the next view to show the name of the previous controller on the back button.

When i get back to that controller i do this:

override func viewWillAppear(_ animated: Bool) {
    self.navigationItem.title = "Title Of View";
    ...
}

The title is set appropriately but it lags for about 1 second or so.. I remember using this techinique for quite some time without having a problem in the past. The code that sets the titles isn't within a network call or anything like that..

Any ideas about what might be causing this?


Solution

  • In order to hide the back button title you should set empty UIBarButtonItem instance to the self.navigationItem.backBarButtonItem right after you push the new view controller, like so:

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

    This way you don't have to manipulate the title of the view controller.