ios - resignFirstResponder and endEditing (even global calls) are not hiding the keyboard -
i have viewcontroller
set delegate uitextfield
. no matter try, can not keyboard hide when calling textfieldshouldreturn
.
my viewdidload
method:
override func viewdidload() { super.viewdidload() self.view.addsubview(newmodelfield) newmodelfield.delegate = self self.presettableview.registerclass(uitableviewcell.self, forcellreuseidentifier: "presetcell") //self.view.becomefirstresponder() }
and textfieldshouldreturn
method:
func textfieldshouldreturn(textfield: uitextfield) -> bool { //uiapplication.sharedapplication().sendaction("resignfirstresponder", to:nil, from:nil, forevent:nil) if(textfield.text! != ""){ items.append(textfield.text!) presettableview.reloaddata() textfield.text! = "" //self.view.resignfirstresponder() //self.addview.resignfirstresponder() //textfield.endediting(true) //self.view.endediting(true) uiapplication.sharedapplication().delegate?.window?!.endediting(true) return false } return true }
you can see commented out attempts have tried whole host of different fixes. know textfieldshouldreturn
being called after debugging print statements. can not figure out why keyboard won't hide.
i tried swapping return true , false statements. tried setting delegate storyboard. tried deleting textfield storyboard, cleaning, , adding in. tried top level calls resignfirstresponder
, endediting
calls these functions textfield , view.
to dismiss keyboard, send resignfirstresponder message text >field first responder. doing causes text >field object end current editing session (with delegate >object’s consent) , hide keyboard.
yourtextfield.resignfirstresponder()
Comments
Post a Comment