简体   繁体   中英

How to customize searchBar scope

So I have been searching everywhere, but can't come to an answer on this. I have a UISearchBar searchBar setup that filters my data. I came across scope functionality, but created my own scope buttons. So my question is, how do I link those buttons I made so that they can perform the same thing as UISearchBar scopes?

The scope buttons are more a convenience than anything else. They don't automatically change the scope of the search. That is something you have to do in response to the user changing the scope.

Normally, you don't make the buttons yourself. You set the titles for the buttons in the scopeButtonTitles property of the search bar, eg:

self.searchController.searchBar.scopeButtonTitles = ["Scope 1", "Scope 2"]

and then in the UISearchBarDelegate delegate implement

func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int)

to act upon the user's choice.

But if there's a great reason to make your own buttons, you just do it all yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM