我正试图在点击背景时辞职,但我不能
首先,我点击了可编辑的文本字段并打开键盘,然后我已经在另一个不可编辑的文本字段上进行了访问,之后我已经使用了背景,但我无法重新设置键盘
这是我的代码
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if(textField == insertcity)
{
[self.view endEditing:YES];
citytable.hidden = NO;
hoteltable.hidden = YES;
[self SetDynamicHieghtofTbl:citytable andArr:cityarray];
}
if(textField == inserthotel)
{
[self.view endEditing:YES];
hoteltable.hidden = NO;
citytable.hidden = YES;
[self SetDynamicHieghtofTbl:hoteltable andArr:hotelarray];
}
if(self.txt_validationCode.tag == 3)
{
//[self.view endEditing:NO];
}
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
if(textField.tag == 3)
{
self.enteredCode = textField.text;
}
}
- (void) backgroundTap: (UITapGestureRecognizer *)recognizer
{
citytable.hidden = YES;
hoteltable.hidden = YES;
[self.txt_validationCode resignFirstResponder];
}
答案 0 :(得分:1)
简单的方法是将UITextField的委托连接到self(self.mytestField.delegate = self)并使用[textField resignFirstResponder]解除方法textFieldShouldReturn中的键盘;
另一种解雇键盘的方法如下:
[self.view endEditing:YES];
放
[self.view endEditing:YES];
您要关闭键盘(按钮事件,触摸事件等)。
答案 1 :(得分:0)
我希望它对你有帮助。
- (void) backgroundTap: (UITapGestureRecognizer *)recognizer
{
[self.view endEditing:YES]; // add this line in your code
citytable.hidden = YES;
hoteltable.hidden = YES;
[self.txt_validationCode resignFirstResponder];
}