Search code examples
iosresignfirstresponder

Hide Keyboard in iOS


I want to hide the keyboard after entering the data.

I have tried both methods which are given below.

[self.textField resignFirstResponser];
[self.view endEditing:YES];

Both are working well but i want to know the difference between these two lines.

Thanks


Solution

  • In general, both the methods are used to hide the keyboard or lose the focus on a TextField. The [self.view EndEditing:YES] tells the program to end any editing process that are taking place in a view (or its subview). Hence, it apparently hides the keyboard that was up for editing. This happens regardless of any specific textfield. Whereas, [self.textField resignFirstResponder] method resigns its response towards editing the specified textField in the method (self.textField). Thus loses focus and hides the keyboard.