ios - Is there a way to create "Search Suggestions" interface with UISearchController -


in app, need create search suggestions interface -- similar google search (it starts displaying suggestions type in search field).

i did uisearchcontroller search bar in navigation bar, set this:

// setup search controller searchcontroller = uisearchcontroller(searchresultscontroller: searchsuggestionscontroller) self.searchcontroller.searchresultsupdater = searchsuggestionscontroller self.searchcontroller.hidesnavigationbarduringpresentation = false self.navigationitem.titleview = self.searchcontroller.searchbar  // issue!! definespresentationcontext needs false or can't push // controller multiple times on navigation stack self.definespresentationcontext = true 

while works fine when search controller pushed navigation stack first time, doesn't let search bar focus when pushed second time, shown below

with definespresentationcontext = true, doesn't let search bar focus second time push search controller on navigation stack

but if set false: start typing search bar, navigation bar (along search bar) disappears. expected behavior since (because of definespresentationcontext = false) uisearchcontroller trying display view on top of uinavigationcontroller's view, shown below:

with definespresentationcontext = false, navigation bar disappears start typing

is there way achieve through uisearchcontroller? if not, pointers on how should create custom control this? (code minimal app shown in animations can downloaded here)

it's not possible use uisearchcontroller this. uisearchbar , uinavigationbar known not play together. decided was, every time user taps search button, check childviewcontrollers array of navigation controller , if find instance of searchviewcontroller in there, pop it. otherwise push it.

// function lives inside uinavigationcontroller subclass , called whenever need display search controller func search() {     if let _ = self.topviewcontroller as? searchviewcontroller {         return     }      var existingsearchcontroller: searchviewcontroller? = nil     childcontroller in self.childviewcontrollers {         if let searchcontroller = childcontroller as? searchviewcontroller {             existingsearchcontroller = searchcontroller         }     }      if let searchcontroller = existingsearchcontroller {         self.poptoviewcontroller(searchcontroller, animated: true)         return     }      self.performseguewithidentifier(storyboardconstants.segueshowsearchcontroller, sender: nil) } 

the proper fix have been, of course, custom control did not have time write custom @ stage.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -