ios - Remove cells when searchBar text is above 0 -


i've created tableview first did set should use filtered array if searchcontroller active. want first when searchbar contain more 0 characters. not seem work. here i've done far in cellforrowatindexpath

    if (count(self.teamsearchcontroller.searchbar.text) > 0) {         team = filteredtabledata[indexpath.row] team         cell.textlabel?.text = team.name string      } else {         team = self.teamarray[indexpath.row] team         cell.textlabel?.font = uifont(name: "helveticaneue-light", size: 20)         cell.textlabel?.text = team.name string      } 

updatesearchresultsforsearchcontroller

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

you should checking length of search text in updatesearchresultsforsearchcontroller

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

update code in cellforrowatindexpath shown below, have check if searchcontroller active or not

if (self.teamsearchcontroller.active) {     team = filteredtabledata[indexpath.row] team  } else {     team = self.teamarray[indexpath.row] team     cell.textlabel?.font = uifont(name: "helveticaneue-light", size: 20) } cell.textlabel?.text = team.name string 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -