0

I have an extension to configure my UINavigationController with large titles which I call in ViewDidLoad of my controller;

extension UINavigationController {
    
    func configure(with title: String) {
        navigationController?.navigationBar.prefersLargeTitles = true
        navigationItem.title = title
        navigationItem.largeTitleDisplayMode = .automatic
    }
}

This extension doesn't seem to be called, however, when I place:

navigationController?.navigationBar.prefersLargeTitles = true

Into my ViewDidLoad, it works as expected. any ideas on why this would be?

David Henry
  • 1,972
  • 20
  • 43

1 Answers1

0

When you call navigationController?.navigationBar.prefersLargeTitles = true it refers to ViewController.navigationController.

But your extension is for UINavigationController so it refers ViewController.navigationController.navigationController

Just replace this:

navigationController?.navigationBar.prefersLargeTitles = true

With this:

navigationBar.prefersLargeTitles = true

and call this in viewDidLoad:

navigationController?.configure(with: "")
ibrahimyilmaz
  • 2,317
  • 1
  • 24
  • 28
  • Thanks, I did the above and it had showed the large title however, it didn't give me the title string. I've now made the extension against the ViewController instead of the NavController. – David Henry Oct 30 '20 at 07:06
  • Yes, it could be an alternative. Glad the problem was solved. – ibrahimyilmaz Oct 30 '20 at 07:23