5

I ran into a strange problem:

  • I have a two view controllers - list, and detail.
  • When I push Detail from List, navigation bar is in colapsed mode.
  • To make title appear large, I have to scroll down.

ListViewController:

...
override func viewDidLoad() {
    super.viewDidLoad()

    setupNavigationBar()
}

private func setupNavigationBar() {
    navigationController?.navigationBar.prefersLargeTitles = true
    navigationItem.largeTitleDisplayMode = .never
}
...

DetailViewController:

...
override func viewDidLoad() {
    super.viewDidLoad()

    setupNavigationBar()
}

private func setupNavigationBar() {
    title = "Bangkok ⇄ Phuket"
    navigationController?.navigationBar.prefersLargeTitles = true
    navigationItem.largeTitleDisplayMode = .always
}
...

After some investigation, I found out that the bug oocurs only when I put certain characters in the title:

  • When the title is "Bangkok → Phuket", everything works as expected
  • When the title is "Bangkok ⇄ Phuket", pushed controller's title is collapsed

Do you guys know what are the restrictions for characters in title, or any ideas how to solve it? Thank you, any help much appreciated

Lachtan
  • 4,803
  • 6
  • 28
  • 34

2 Answers2

1

In your DetailViewController try placing your Navigation Bar customisations into your viewWillAppear method:

override func viewWillAppear(_ animated: Bool) {
    navigationController?.navigationBar.prefersLargeTitles = true
    navigationItem.largeTitleDisplayMode = .always
}
hfelpp
  • 403
  • 2
  • 6
1

Use navigationController?.navigationItem.largeTitleDisplayMode = .always instead of navigationItem.largeTitleDisplayMode = .always fixed the issue for me.

navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationItem.largeTitleDisplayMode = .always

This issue indicates that there are differences between navigationController.navigationItem and self.navigationItem of viewController. Be aware on using it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Simon
  • 237
  • 1
  • 7