ios8 - Displaying search bar in navigation bar in iOS 8 -


uisearchdisplaycontroller had boolean property called displayssearchbarinnavigationbar. what's equivalent in ios 8 have search bar move there? guidance appreciated.

here's code, i'm not entirely sure why isn't working. when click search bar, disappears instead of moving , navigation bar up.

import uikit  class viewcontroller: uiviewcontroller, uisearchresultsupdating, uisearchcontrollerdelegate, uisearchbardelegate, uitableviewdelegate, uitableviewdatasource {  let searchcontroller = uisearchcontroller(searchresultscontroller:  nil)  var tableview = uitableview()  override func viewdidload() {     super.viewdidload()     // additional setup after loading view, typically nib.      self.searchcontroller.searchresultsupdater = self     self.searchcontroller.delegate = self     self.searchcontroller.searchbar.delegate = self      self.searchcontroller.hidesnavigationbarduringpresentation = true     self.searchcontroller.dimsbackgroundduringpresentation = true      tableview.datasource = self     tableview.delegate = self       self.navigationitem.titleview = searchcontroller.searchbar       self.definespresentationcontext = true      self.setupsearchbar()     }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) {  }  func setupsearchbar() {      // set search bar position , dimensions     var searchbarframe: cgrect = self.searchcontroller.searchbar.frame     var viewframe = self.view.frame     self.searchcontroller.searchbar.frame = cgrectmake(searchbarframe.origin.x, searchbarframe.origin.y + 64,viewframe.size.width, 44)       // add search controller's search bar our view , bring forefront     self.view.addsubview(self.searchcontroller.searchbar)  }  func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     var cell = uitableviewcell()      return cell }  func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return 5 } } 

according apple :

uisearchdisplaycontroller deprecated in ios 8. (note uisearchdisplaydelegate deprecated.) manage presentation of search bar , display search results in ios 8 , later, instead use uisearchcontroller.

the uisearchcontroller class defines interface manages presentation of search bar in concert search results controller’s content. search results controller, uiviewcontroller object specified searchresultscontroller property, manages results of search.

now can use uisearchcontroller show search bar in navigation bar in following way:

class viewcontroller: uiviewcontroller, uisearchcontrollerdelegate, uisearchresultsupdating, uisearchbardelegate {      var searchcontroller : uisearchcontroller!      override func viewdidload() {        super.viewdidload()         self.searchcontroller = uisearchcontroller(searchresultscontroller:  nil)         self.searchcontroller.searchresultsupdater = self        self.searchcontroller.delegate = self        self.searchcontroller.searchbar.delegate = self         self.searchcontroller.hidesnavigationbarduringpresentation = false        self.searchcontroller.dimsbackgroundduringpresentation = true         self.navigationitem.titleview = searchcontroller.searchbar         self.definespresentationcontext = true             }      func updatesearchresults(for searchcontroller: uisearchcontroller) {      }      override func didreceivememorywarning() {        super.didreceivememorywarning()        // dispose of resources can recreated.     } } 

but have consider need set uinavigationcontroller in storyboard :

enter image description here

you can easy select viewcontroller , see following steps:

enter image description here

and should see in device when make click in search bar following picture:

enter image description here

i hope you


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 -