objective-c - 无法关闭键盘

标签 objective-c ios uitextfield

当完成或触摸文本字段之外的内容时,我不知道如何关闭键盘。这是我尝试的方法

myController.h

@interface myController : UIViewController <UITextFieldDelegate>{
    secondViewController *secondView;
}

myController.m

-(void)loadView
{
    .....
    textFieldRounded.borderStyle = UITextBorderStyleRoundedRect;
    textFieldRounded.textColor = [UIColor blackColor]; 
    textFieldRounded.font = [UIFont systemFontOfSize:17.0];
    textFieldRounded.placeholder = @"<enter text>";  
    textFieldRounded.backgroundColor = [UIColor whiteColor]; 
    textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo;    
    textFieldRounded.keyboardType = UIKeyboardTypeDefault;  
    textFieldRounded.returnKeyType = UIReturnKeyDone;  
    textFieldRounded.clearButtonMode = UITextFieldViewModeWhileEditing;    
    [textFieldRounded.delegate = self;        
    [self.view addSubview:textFieldRounded];

    ....
}

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    return [textField resignFirstResponder];
}

最佳答案

用途:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {

当您触摸文本字段之外时进行捕获

关于objective-c - 无法关闭键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9113264/

相关文章:

iphone - 更改 UINavigationBar 中 UIBarButtonItem 的位置

objective-c - 新手试图理解 .h 文件中的多个 @interface

ios - 在malloc_error_break中设置一个断点进行调试

ios - 通过从数组中删除项目来删除 tableView 中的项目会发生 fatal error : Index out of range

ios - 将 Button 添加到常量可变 TableView

ios - 在 UITextField 中插入文本后不需要的 UIView 框架重置

ios - 在 View Controller 之间传递数据

ios - 在 Storyboard 中使用错误的尺寸等级进行了更改

objective-c - 我的 UI 上的 NSTextField 需要通过标签访问它们

ios - 单元测试 UITextField 方法