hiding keyboard ios [duplicate]

霸气de小男生 提交于 2019-11-27 03:20:30

If you want to hide the keyboard when you tap a button and you have more than one UITextFields in your view, then you should use:

[self.view endEditing:YES];

Tap anywhere on the view, and the keyboard will disappear.

user2248428

Try this:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
     [[self view] endEditing:YES];
}

You can also iterate through an array of views (such as your UIView's subviews) and manually resign the keyboard, this is good if you dont want to resign on ALL the subviews within your parent UIView.

- (void)viewDidLoad
{
    self.view.userInteractionEnabled = TRUE;
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    //Iterate through your subviews, or some other custom array of views
    for (UIView *view in self.view.subviews)
        [view resignFirstResponder];
}
Sonu

You can try UITouch method, and in this set your text field object and call resignFirstResponder when ever you touch on the screen the keyboard will resign, I hope this will work for you.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{  
    [currentSelectedTextField resignFirstResponder];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!