theUturn theUturn - 1 year ago 174
Swift Question

How to disable or hide the scope buttons in searchbar?

I am new to ios I am using Xcode 7 and swift 2 I have implemented a searchbar controler with my

like this:

searchController.searchResultsUpdater = self
searchController.searchBar.delegate = self
definesPresentationContext = false
searchController.dimsBackgroundDuringPresentation = false

// Setup the Scope Bar
searchController.searchBar.scopeButtonTitles = ["All", "Chocolate"]
searchController.searchBar.showsScopeBar = false
searchController.searchBar.searchBarStyle = .Default
tableView.tableHeaderView = searchController.searchBar

But I don't want the scope buttons in this case. How can I hide them?

Note, this is not working for me:

searchController.searchBar.showsScopeBar = false

Answer Source


Using Search Display Controller via storyboard, go to the search bar attributes inspector and uncheck the "Shows Scope Bar" if it is checked.and remove the scope titles if any.


Using Search Display Controller programmatically then you have to remove this part, will not show the scope bar

searchController.searchBar.scopeButtonTitles = ["All", "Chocolate"]
searchController.searchBar.showsScopeBar = false


Make the scopeButtonTitles to nil will also remove the buttons in scope bar

searchController.searchBar.scopeButtonTitles = nil
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download