1

I've used this code in my main UIViewController to have a large title:

navigationController?.navigationBar.prefersLargeTitles = true

But I don't want that to happen in every view, indeed I just want that large title in my main view.

So, reading online, I've seen that to achieve this I needed to add this in my views in which I did not want that large title:

navigationController?.navigationItem.largeTitleDisplayMode = .never

But that's not really working as expected.

The result that I'm getting is that when I perform a segue, the title disappears, but the navigation controller maintains the same size as if there was a large title inside it.

What could be wrong with my implementation?

iOS 12.1 Beta 3
Xcode 10.1 Beta 2

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223

1 Answers1

1

You should change largeTitleDisplayMode to .never for the navigationItem of your view controller instead.

navigationItem.largeTitleDisplayMode = .never

Alternatively, if you're working with storyboards, you can set the Large Title option to Never inside the Attributes inspector of your navigation item:

Navigation Item settings - Large Title set to Never

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
  • Tried that too without success. `func setupNavigationTitle() { navigationItem.title = "Counters"; navigationController?.navigationBar.prefersLargeTitles = true; navigationController?.navigationItem.largeTitleDisplayMode = .never; }` –  Oct 10 '18 at 22:52
  • @matt.logic Please show your exact setup in the question. Also, try to create a view controller setup with just the above mentioned code and see whether the issue persists. – Tamás Sengel Oct 10 '18 at 22:55
  • Ok I've read that incorrectly, that fixed the problem! Many thanks! If I can ask, what is the difference between the navigationController.navigationItem and the simple navigationItem? –  Oct 10 '18 at 22:56
  • @matt.logic Replace `navigationController?.navigationItem.largeTitleDisplayMode = .never` with `navigationItem.largeTitleDisplayMode = .never`, as mentioned in the answer. – Tamás Sengel Oct 10 '18 at 22:56
  • @matt.logic You welcome! Every `UIViewController` instance has a `navigationItem` property. Since `UINavigationController` is a subclass of `UIViewController`, it also has one. However, the navigation item of a view controller in a navigation stack overrides the navigation item of the `UINavigationController` itself (this behavior lets you assign different navigation item titles for every VC in the stack). – Tamás Sengel Oct 10 '18 at 22:59