1

I have a tab bar app where one of the views is a UITableViewController containing static cells as content with 1 section and 1 row.

Chat View

I want the Large Title to be set to "Always," so I made the selection on the storyboard and the title was large on the simulator. Now when the user taps "Start Chat," the app will segue to the Virtual Assistant View Controller, where the Large Title is set to "Never" on the storyboard. Now the problem is that when the user segues back to the previous view controller with the "Start Chat" table view cell, the title is not large anymore.

It is interesting that when I set the table view to be scrollable, the title becomes large again upon dragging down the table view. I made sure the navigation bar on the Navigation Controller storyboard is checked with the "Prefers Large Titles." I am using Xcode 11, and this was not a problem when using Xcode 10.

I tried creating a custom class for the view with the start chat button and this code did not work in making the title large from a segue back:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    navigationController?.navigationItem.largeTitleDisplayMode = .always
    navigationController?.navigationBar.prefersLargeTitles = true

What else could I do? Any help will be greatly appreciated!

William Chiang
  • 85
  • 2
  • 12

2 Answers2

4

I'd use willMove(toParent:) to change the title back before the segue is performed.

override func willMove(toParent parent: UIViewController?) {
    navigationController?.navigationItem.largeTitleDisplayMode = .always
    navigationController?.navigationBar.prefersLargeTitles = true
}
excitedmicrobe
  • 2,338
  • 1
  • 14
  • 30
0

Set the properties when setting up the UINavigationController, before presenting it. If you already presented the navigation controller, try doing this to force-update the navigation bar:

navigationController?.navigationItem.prompt = ""

navigationController?.navigationItem.prompt = nil

I took this workaround from this question.

In your particular case, it would be better to subclass the navigation controller and set those properties in its viewDidLoad method, so its properties (largeTitleDisplayMode and prefersLargeTitles) are set in a self-contained code.

Alejandro Iván
  • 3,969
  • 1
  • 21
  • 30