theUturn theUturn - 1 month ago 29
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

tableViewController
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

Storyboard

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.

Programmatically

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

Or

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

searchController.searchBar.scopeButtonTitles = nil
Comments