Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 UISearchController disappearing when typing

iOS 11 search bar keeps disappearing when typing i have tried to set the searchController.hidesNavigationBarDuringPresentation = false also the searchController.definesPresentationContext = true here is a video of what is going on

Video

My delegate function

func updateSearchResults(for searchController: UISearchController) {
    filarr = arr.filter({ (arr:String) -> Bool in
        if arr.contains(searchController.searchBar.text!){
            return true
        }else{
            return false
        }

    })
    resultController.tableView.reloadData()
}

//Assigning the searchbarcontroller
if #available(iOS 11.0, *) {
        self.navigationController?.navigationBar.prefersLargeTitles = true
        self.navigationItem.searchController = searchController
        self.navigationItem.hidesSearchBarWhenScrolling = false
    } else {
        tableView.tableHeaderView = searchController.searchBar
    }
like image 993
Sagaya Abdul Avatar asked Dec 08 '25 17:12

Sagaya Abdul


1 Answers

You need to set definesPresentationContext to true on the view controller which presents your searchController.

Your are doing this:

searchController.definesPresentationContext = true

but should do this:

definesPresentationContext = true
like image 189
Au Ris Avatar answered Dec 11 '25 09:12

Au Ris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!