P. 348/Chap 16 -- Fix the Titles

Can you explain how setting:

navigationItem.largeTitleDisplayMode = .never

in the ChecklistViewController affects what is displayed for the AllLIstsViewController? My solution had the following line instead:

navigationController?.navigationBar.prefersLargeTitles = false

and with my code if I tap on a checklist in the AllListsViewController, which takes me to the ChecklistViewController, and then I tap on the back button, which takes me back to the AllListsViewController, the title at the top of the table will change to small type–even though the AllListsViewController sets the navigation bar to prefer large titles. With the .never line instead of my code, the title for the AllListsViewController table is displayed in large type after I hit the back button.

@hollance @fahim Do you have any feedback regarding this? Thank you - much appreciated! :]

Setting largeTitleDisplayMode to .never in ChecklistViewController should not affect anything in AllLIstsViewController if that was your main question. I wasn’t quite clear if that was the question or if you were wondering about how navigating back from ChecklistViewController affected the titles in AllLIstsViewController after your custom changes since that’s a separate issue …

To take this as two separate items, let’s take setting navigationItem.largeTitleDisplayMode = .never in ChecklistViewController first. This simply forces the navigation bar to display small titles for the ChecklistViewController explicitly. How titles are displayed in other view controllers (such as AllLIstsViewController) would depend on how those particular view controllers are set up). This is why we set the overall navigation bar for the app to display large titles by default with the navigationController?.navigationBar.prefersLargeTitles = true line which is moved to AllLIstsViewController, which is the initial view controller at this point.

So, with that set up, when you first start the app, the initial view controller would show large titles since it would have the following settings:
navigationController?.navigationBar.prefersLargeTitles = true

Your ChecklistViewController is explicitly turning off these large titles for its navigation item only by using the following line in its viewDidLoad:
navigationItem.largeTitleDisplayMode = .never

But when you go back to the previous view, the default setting for the navigation bar as a whole (not the navigation item) kicks in and you get large titles.

When you use navigationController?.navigationBar.prefersLargeTitles = false in ChecklistViewController, that changes the settings for the navigation bar as a whole, not your current navigation item. So, now your navigation bar is set to not show large titles. So, when you go back to AllLIstsViewController, that will show small titles too since viewDidLoad is executed only once and the setting of large titles in AllLIstsViewController happened the first time that view is loaded - it is not reloaded when you go back from ChecklistViewController since there in an instance of AllLIstsViewController in the navigation stack. So you simply have the navigation bar now at the following state when you go back to AllLIstsViewController:
navigationController?.navigationBar.prefersLargeTitles = false

So, you get small titles this time around for AllLIstsViewController.

Hope that makes sense?

if you were wondering about how navigating back from ChecklistViewController affected the titles in AllLIstsViewController after your custom changes

That’s it. Thanks for the explanation fahim. :sunny:

This topic was automatically closed after 166 days. New replies are no longer allowed.