swift3 - Make Search Bar Become First Responder -


i have uisearchcontroller inside of uinavigationbar. user has tap on uibarbuttonitem, in instantiate new uiviewcontroller present it, in order begin searching.

class viewcontroller: uiviewcontroller {    var searchcontroller: uisearchcontroller!     override func viewdidload() {     super.viewdidload()     setupsearchcontroller()   }    func setupsearchcontroller() {     searchcontroller = uisearchcontroller(searchresultscontroller: nil)     searchcontroller.searchbar.delegate = self     searchcontroller.searchresultsupdater = self     searchcontroller.searchbar.showscancelbutton = true     searchcontroller.dimsbackgroundduringpresentation = false     searchcontroller.hidesnavigationbarduringpresentation = false      definespresentationcontext = true     navigationitem.titleview = searchcontroller.searchbar   } } 

i've done plenty of research before hand, still can't manage find solution...

help in making search controller become first responder appreciated.

do this,

extension searchmovieviewcontroller: uisearchcontrollerdelegate {    func didpresentsearchcontroller(_ searchcontroller: uisearchcontroller) {     searchcontroller.searchbar.becomefirstresponder()   } } 

you want searchbar firstresponder not searchcontroller , should work.


Comments

Popular posts from this blog

c++ - CPP, 'X' button listener -

shared memory - gstreamer shmsrc and shmsink with h264 data -

r - Add string of (variable number of) arguments to a function within a function -