0
votes

I need to show large navigation title while search with searchBar, but when I'm clicking on Searchbar or starting to type my NavigationTitle is replaced with SearchBar. I checked methods for navigationItem and didn't find any suitable.

Does anybody know how can we always show title, even while searching? Here is my code

    class FavouriteVC: UIViewController {
        let searchController = UISearchController(searchResultsController: nil)
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            view.backgroundColor = .white
            
            navigationController?.navigationBar.prefersLargeTitles = true
            navigationItem.title = "Favourite"
            navigationItem.searchController = searchController
            navigationItem.largeTitleDisplayMode = .always
        }
    }

And here are shots screen with NavTitle screen without NavTitle

1
Hey! If I'm not mistaken, my answer should work for you. - Lokesh SN

1 Answers

0
votes

Seems like UISearchController has a hidesNavigationBarDuringPresentation that prevents the navigation bar from hiding when set to false

Include:

searchController.hidesNavigationBarDuringPresentation = false

in your viewDidLoad and if I've understood your issue right, this should do what you need.