Scopebar hide / show UISearchController

379 views Asked by At

I want to have a button that hides and shows the scope bar. Seems simple. But It only works before an actual search. After searching the animation happens to show the search bar, but it isn't there. Any suggestions? NOTE: I am using the bookmark button with my own custom image to show / hide the scopebar.

Video of Issue Here

func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) {
   DispatchQueue.main.async(execute: {

    self.isFilter = self.isFilter ? false : true
    self.searchController.searchBar.scopeButtonTitles = self.isFilter ? ["First Name", "Last Name", "Unit"] : nil

    self.searchController.searchBar.showsScopeBar = self.isFilter

    self.searchController.searchBar.sizeToFit()
    self.tableView.reloadSections(IndexSet(0..<1), with: .automatic)
    })

 }

I also have this in updateSearchResults:

    if searchController.isActive {
        searchController.searchBar.showsBookmarkButton = false
    } else {
        searchController.searchBar.showsBookmarkButton = true
    }
0

There are 0 answers