Sunny Summer
Sunny Summer

Reputation: 41

Need to show navigation title while using searchBar in navigationBar

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

Upvotes: 1

Views: 600

Answers (1)

Lokesh SN
Lokesh SN

Reputation: 1593

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.

Upvotes: 1

Related Questions