iOS Swift: SearchController with a StoryBoard UISearchBar -


evening, have built search controller, , have code programmatically create search bar. replace code search bar designed in story board.

so question is, how can connect outlet search controller?

this code:

public class customsearchcontroller: uisearchcontroller {      public var customsearchbar = uisearchbar()      override public var searchbar: uisearchbar {         {             return self.customsearchbar         }     } }  func configuresearchcontroller() {      searchcontroller = customsearchcontroller()     searchcontroller.searchresultsupdater = self     searchcontroller.dimsbackgroundduringpresentation = false     searchcontroller.hidesnavigationbarduringpresentation = false     searchcontroller.customsearchbar = self.customsearchbar      searchcontroller.searchbar.delegate = self      self.definespresentationcontext = true  }  extension earthsearchertableviewcontroller : uisearchresultsupdating {      public func updatesearchresults(for searchcontroller: uisearchcontroller) {         //code         guard let text = searchcontroller.searchbar.text else { return }          self.getlocations(forsearchstring: text)     }      fileprivate func getlocations(forsearchstring searchstring: string) {          let request = mklocalsearchrequest()         request.naturallanguagequery = searchstring         request.region = mapview.region          let search = mklocalsearch(request: request)         search.start { (response, error) in              guard let response = response else { return }             self.locations = response.mapitems             self.tableview.reloaddata()         }     }      @objc func zoomtocurrentlocation() {           //clear existing pins         mapview.removeannotations(mapview.annotations)         mapview.removeoverlays(mapview.overlays)          let annotation = mkpointannotation()         annotation.coordinate = mapview.userlocation.coordinate         mapview.addannotation(annotation)          let span = mkcoordinatespanmake(0.005, 0.005)         let region = mkcoordinateregionmake(mapview.userlocation.coordinate, span)         mapview.setregion(region, animated: true)          let location = cllocation(latitude: mapview.userlocation.coordinate.latitude, longitude: mapview.userlocation.coordinate.longitude)         mapview.add(mkcircle(center: location.coordinate, radius: 50))       }  } 

i think have problem delegates, because when type in search bar, results not show off in table

any tips?

subclass uisearchcontroller , override searchbar getter return searchbar want.

public class mysearchcontroller: uisearchcontroller {      public var customsearchbar = uisearchbar()     override public var searchbar: uisearchbar {         {             return customsearchbar         }     } } 

in method, set customsearchbar searchbar.

func configuresearchcontroller() {         searchcontroller = mysearchcontroller()     searchcontroller.customsearchbar = self.searchbar     //other stuff... } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -