ios - Why is my tableview blank after using UISearchResultsUpdating cancel button? -


i have tableview loads function , displays data in viewdidappear. same tableview (i assume) used when user taps on searchbar in navigation title, , searches query.

the problem after user taps cancel button: function calling original data performs , prints correct data, doesn't appear on screen after tableview.reloaddata.

i've tried placing function in various places (didcancel, didendediting), , function called/correctly returns data, doesn't appear on table.

any suggestions or workarounds?

class locationviewcontroller: uiviewcontroller, uitableviewdelegate, uitableviewdatasource, uisearchresultsupdating, uisearchbardelegate, uisearchcontrollerdelegate {  override func viewdidload() {     super.viewdidload()     tableview.delegate = self     tableview.datasource = self }  override func viewwillappear(animated: bool) {         self.load0()         tableview.reloaddata()      self.locationsearchcontroller = ({         let controller = uisearchcontroller(searchresultscontroller: nil)         controller.searchresultsupdater = self         controller.hidesnavigationbarduringpresentation = false         controller.dimsbackgroundduringpresentation = false         controller.searchbar.delegate = self         controller.searchbar.searchbarstyle = .minimal         controller.searchbar.sizetofit()         self.navigationitem.titleview = controller.searchbar         return controller     })() }  //below try remove search data , reload original data. override func viewdiddisappear(animated: bool) {     self.locationsearchcontroller.active = false }  func searchbartextdidbeginediting(searchbar: uisearchbar) {     self.searchdata.removeallobjects()     self.category.removeall(keepcapacity: false)     self.product.removeall(keepcapacity: false)     self.users.removeall(keepcapacity: false) self.load0()     tableview.reloaddata() }   func searchbartextdidendediting(searchbar: uisearchbar) {     self.searchdata.removeallobjects()     self.category.removeall(keepcapacity: false)     self.product.removeall(keepcapacity: false)     self.users.removeall(keepcapacity: false) self.load0() tableview.reloaddata()  }  func searchbarcancelbuttonclicked(searchbar: uisearchbar) { self.searchdata.removeallobjects()     self.category.removeall(keepcapacity: false)     self.product.removeall(keepcapacity: false)     self.users.removeall(keepcapacity: false)        self.load0()         tableview.reloaddata() } 

the function performs search updatesearchresultsforsearchcontroller:

func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) { query , places items in array that's displayed original tableview } 

i wondered if there tableview being used not aware of, it's clear searchcontroller using original tableview because follows design reusable cell.

you must fill uitableview way:

override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         if self.searchdisplaycontroller!.active {             return self.filtereddata.count         }         return self.defaultddata.count     }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         var cell = self.tableview.dequeuereusablecellwithidentifier("cell") as! uitableviewcell          if self.searchdisplaycontroller!.active {             cell.textlabel.text = self.filtereddata[indexpath.row]         } else {             cell.textlabel.text = self.defaultdata[indexpath.row]         }          return cell     } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -