0

I am on a viewController having textField being first responder, then a view gets instantiated on some call back method, but the keyboard still gets open on the instantiated viewController, I have tried to dismiss the keyboard by [self.view endEditing:YES] but it wont work.

AsimRazaKhan
  • 2,154
  • 3
  • 22
  • 36

3 Answers3

1

try adding the [self.view endEditing:YES] in viewDidDisappear

BXV
  • 405
  • 3
  • 16
0

Use default overide function of viewcontroller

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    view.endEditing(true)
}
Sand'sHell811
  • 358
  • 3
  • 15
0

hi go to mainStoryBoard and just check the checkMark on auto enable returnkey if it is same as you mainStoryBoard so then return back to your code

/// the method where  view is getting instantialte before view get Instantite use this here is sample.

  [self resignKeyBoard];

enter image description here

// goto your code here is uiButton with close icon 

 - (IBAction)closeKeyboardPressed:(id)sender {

 cellTypeButton*btn=(cellTypeButton*)sender;

if(btn.selected){
    btn.selected=false;
    [self resignKeyBoard];
}else{
    btn.selected=true;
    [self resignKeyBoard];
}

}


-(void)resignKeyBoard{

closeKeyBoardBtn.hidden=true;

[PhoneNumTxt resignFirstResponder];
[codeTxt1 resignFirstResponder];
[usernameField resignFirstResponder];
[fullnameField resignFirstResponder];
[statusField resignFirstResponder];
[Utilities animateDownTextField:PhoneNumTxt inView:self.view];
[Utilities animateDownTextField:codeTxt1 inView:self.view];
[Utilities animateDownTextField:usernameField inView:self.view];
[Utilities animateDownTextField:fullnameField inView:self.view];
[Utilities animateDownTextField:statusField inView:self.view];

[self.view endEditing:YES];
}



 //// have a good day :D
Nayab Khan
  • 21
  • 6