在ios应用程序中隐藏键盘
当我显示选项表时,我有隐藏键盘的问题 我的代码中的问题在哪里在ios应用程序中隐藏键盘,ios,alert,Ios,Alert,当我显示选项表时,我有隐藏键盘的问题 我的代码中的问题在哪里 - (void)optionsSheet2{ if(optionsSheet2) { [optionsSheet2 dismissWithClickedButtonIndex:-1 animated:YES]; optionsSheet2 = nil; } optionsSheet2 = [[UIActionSheet alloc] initWithTitle:nil del
- (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];
}
您可以这样更改代码:
- (void)optionsSheet2
{
[self.view endEditing:YES];
}
使用这个简单的解决方案
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
适用于UITextField、UITextView和所有子视图。您是否正确添加了委托方法?您能否更清楚地回答您的问题?我有UIActionSheetDelegate和UISearchBarDelegatechech这行代码:[self.parentViewController.view endEditing:是];它也不起作用:(如果我不使用选项,请说明它的作用。