我在一个viewController上,textField是第一个响应者,然后一个视图在一些回调方法上实例化,但键盘仍然在实例化的viewController上打开,我试图通过[self.view endEditing:YES]
解除键盘但是它不会工作。
答案 0 :(得分:1)
尝试在viewDidDisappear中添加[self.view endEditing:YES]
答案 1 :(得分:1)
您可以转到mainStoryBoard,如果它与mainStoryBoard相同,只需检查自动启用返回键上的checkMark,然后返回到您的代码
/// the method where view is getting instantialte before view get Instantite use this here is sample.
[self resignKeyBoard];
// 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
答案 2 :(得分:0)
使用viewcontroller的默认覆盖功能
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
view.endEditing(true)
}