ios - I have working search bar, when i move it to navigation bar, it stopped working swift -


i have search bar search bar controller , table view , working.

image: enter image description here

here code:

class searchviewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate, uisearchdisplaydelegate, uisearchbardelegate {  @iboutlet var searchbar: uisearchbar! @iboutlet var tableview: uitableview! var friendsarray = [frienditem]() var filteredfriends = [frienditem]()  override func viewdidload() {     super.viewdidload()      //var leftnavbarbutton = uibarbuttonitem(customview:searchbar)     //self.navigationitem.leftbarbuttonitem = leftnavbarbutton      self.friendsarray += [frienditem(name: "test1")]     self.friendsarray += [frienditem(name: "test2")]     self.friendsarray += [frienditem(name: "test3")]      self.tableview.reloaddata()      //var leftnavbarbutton = uibarbuttonitem(customview: searchbar)     //self.navigationitem.leftbarbuttonitem = leftnavbarbutton }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  func numberofsectionsintableview(tableview: uitableview) -> int {     return 1 }  func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     if (tableview == self.searchdisplaycontroller?.searchresultstableview)     {         return self.filteredfriends.count     }     else     {         return self.friendsarray.count     } }  func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = self.tableview.dequeuereusablecellwithidentifier("cell") as! uitableviewcell      var friend : frienditem      if (tableview == self.searchdisplaycontroller?.searchresultstableview)     {         friend = self.filteredfriends[indexpath.row]     }     else     {         friend = self.friendsarray[indexpath.row]     }      cell.textlabel?.text = friend.name      return cell }   func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {     tableview.deselectrowatindexpath(indexpath, animated: true)      var friend : frienditem      if (tableview == self.searchdisplaycontroller?.searchresultstableview)     {         friend = self.filteredfriends[indexpath.row]     }     else     {         friend = self.friendsarray[indexpath.row]     }      println(friend.name)    }  func filtercontetnforsearchtext(searchtext: string, scope: string = "title") {     println(searchtext)      self.filteredfriends = self.friendsarray.filter({( friend : frienditem) -> bool in         var categorymatch = (scope == "title")          var stringmatch = friend.name.rangeofstring(searchtext)          return categorymatch && (stringmatch != nil)     }) }  func searchdisplaycontroller(controller: uisearchdisplaycontroller, shouldreloadtableforsearchstring searchstring: string!) -> bool    {     self.filtercontetnforsearchtext(searchstring, scope: "title")     return true }  func searchdisplaycontroller(controller: uisearchdisplaycontroller, shouldreloadtableforsearchscope searchoption: int) -> bool {        self.filtercontetnforsearchtext(self.searchdisplaycontroller!.searchbar.text, scope: "title")      return true    } } 

i need move search bar navigation bar, have looks this:

enter image description here

i found this:

var leftnavbarbutton = uibarbuttonitem(customview: searchbar) self.navigationitem.leftbarbuttonitem = leftnavbarbutton 

but searching totally stopped working. think loose preference of searchbar.

any idea, how can this?

i have it.

    var searchbars:uisearchbar = uisearchbar(frame: cgrectmake(0, 0, 200, 20)) 

and in viewdidload

 var leftnavbarbutton = uibarbuttonitem(customview: searchbars)  self.navigationitem.leftbarbuttonitem = leftnavbarbutton 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -