繁体   English   中英

在iOS应用中隐藏键盘

[英]Hide keyboard in ios app

当我显示optionsSheet时,隐藏键盘有问题。

我的代码中的问题出在哪里?

- (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和所有子视图一起使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM