xcode - UISearchController not updating -


i developing using xcode 6.2 in ios8 , swift, trying implement uisearchcontroller inside uitableviewcontroller updated after search, wrote simple code check if works, when compile, search bar there, when enter text , hit search, nothing happens:

here code:

import uikit  class searchresult: uitableviewcontroller,uisearchbardelegate, uisearchcontrollerdelegate, uisearchresultsupdating {      var result:[string] = ["a","b","c"]      override func viewdidload() {         super.viewdidload()          var searchcon = uisearchcontroller(searchresultscontroller: self)         searchcon.delegate = self         searchcon.searchbar.delegate = self         searchcon.searchbar.sizetofit()         self.tableview.tableheaderview = searchcon.searchbar         searchcon.searchresultsupdater = self         searchcon.searchbar.showssearchresultsbutton = true         self.definespresentationcontext = true         searchcon.dimsbackgroundduringpresentation = false      }      override func didreceivememorywarning() {         super.didreceivememorywarning()     }      override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         var cell:uitableviewcell = self.tableview.dequeuereusablecellwithidentifier("cell") uitableviewcell         cell.textlabel!.text = result[indexpath.row]         return cell     }      override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int     {         return result.count     }       override func numberofsectionsintableview(tableview: uitableview) -> int {         return 1     }       func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) {          println("updating")         result = ["1"]         self.tableview.reloaddata()        } } 

as praveen gowda iv said, wanna change searchresultscontroller self nil. need declare searchcon outside viewdidload:

var searchcon = uisearchcontroller(searchresultscontroller: nil)  override func viewdidload() {     // implementation } 

however, behaviour might not want because updatesearchresultsforsearchcontroller gets called before search:

called when search bar becomes first responder or when user makes changes inside search bar. (apple)


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -