ios - Unable to get rid of the cancel button -


i using search display controller, , in cases not need cancel button

yet in searchbarshouldbeginediting setting showscancelbutton no, or setshowscancelbutton:animated:

does no work

what can rid of button ?

easy solution in swift3 - need make customsearchbar without cancel button , override corresponding property in new customsearchcontroller:

class customsearchbar: uisearchbar {  override func setshowscancelbutton(_ showscancelbutton: bool, animated: bool) {     super.setshowscancelbutton(false, animated: false) }}  class customsearchcontroller: uisearchcontroller { lazy var _searchbar: customsearchbar = {     [unowned self] in     let customsearchbar = customsearchbar(frame: cgrect.zero)     return customsearchbar     }()  override var searchbar: uisearchbar {     {         return _searchbar     } }} 

in myviewcontroller initialize , configure searchcontroller using new custom subclass:

    var videosearchcontroller: uisearchcontroller = ({     // display search results in separate view controller     //        let storyboard = uistoryboard(name: "main", bundle: bundle.main)     //        let alternatecontroller = storyboard.instantiateviewcontroller(withidentifier: "atv") as! alternatetableviewcontroller     //        let controller = uisearchcontroller(searchresultscontroller: alternatecontroller)     let controller = customsearchcontroller(searchresultscontroller: nil)     controller.searchbar.placeholder = nslocalizedstring("enter keyword (e.g. iceland)", comment: "")     controller.hidesnavigationbarduringpresentation = false     controller.dimsbackgroundduringpresentation = false     controller.searchbar.searchbarstyle = .minimal     controller.searchbar.sizetofit()     return controller })() 

and works , smooth! :-)


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -