ios - How to use scope bar with UISearchController -


i able create scope bar uisearchcontroller & set titles

    resultsearchcontroller = ({          let controller = uisearchcontroller(searchresultscontroller: nil)          controller.searchresultsupdater = self          controller.dimsbackgroundduringpresentation = false          controller.searchbar.showsscopebar = true          controller.searchbar.scopebuttontitles = ["one", "two", "three"]          controller.searchbar.sizetofit()          self.tableview.tableheaderview = controller.searchbar           return controller      })() 

but how sort using scope bar. current sorting method follows

func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) {      filteredtabledata.removeall(keepcapacity: false)      let searchpredicate = nspredicate(format: "self contains[c] %@", searchcontroller.searchbar.text)      let array = (tabledata nsarray).filteredarrayusingpredicate(searchpredicate)      filteredtabledata = array as! [string]      tableview.reloaddata()  } 

even though late, might someone! suppose have object person , array of filteredpeople keep people you've filtered, then

struct person {   let name:string }  func updatesearchresultsforsearchcontroller(searchcontroller:uisearchcontroller) {     //start filtering when user starts write     if searchcontroller.searchbar.text.length > 0     {         filteredpeople.removeall(keepcapacity: false)         self.filtercontentforsearchtext(searchcontroller.searchbar.text)         self.tableview.reloaddata()     }     else     {         self.filteredpeople = self.people         self.tableview.reloaddata()     } }  func filtercontentforsearchtext(searchtext: string) {    self.filteredpeople = self.people.filter({( person: person) -> bool in     //in case searching all, , search case insensitive          let categorymatch = (scope == "all")    let stringmatch = person.name.rangeofstring(searchtext, options: nsstringcompareoptions.caseinsensitivesearch)    return categorymatch && (stringmatch != nil)   }) } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -