[英]Hide keyboard in ios app
I have problem with hide keyboard when I showed optionsSheet. 当我显示optionsSheet时,隐藏键盘有问题。
Where is the problem in my code? 我的代码中的问题出在哪里?
- (void)optionsSheet2{
if(optionsSheet2) {
[optionsSheet2 dismissWithClickedButtonIndex:-1 animated:YES];
optionsSheet2 = nil;
}
optionsSheet2 = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Delete", nil), NSLocalizedString(@"Delete all", nil), nil];
[optionsSheet2 showInView:self.parentViewController.view];
}
- (void)dismissKeyboard {
[_uiSearchBar resignFirstResponder];
[_uiSearchBar setShowsCancelButton:NO animated:YES];
[_uiSearchBar setHidden:true];
[self.view endEditing:YES];
}
you change code like this: 您可以这样更改代码:
- (void)optionsSheet2
{
[self.view endEditing:YES];
}
Use this simple Solution 使用这个简单的解决方案
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
Works with UITextField, UITextView and all subviews. 与UITextField,UITextView和所有子视图一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.