Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

[self.view endEdtiting:YES]; 

From Docs:

"Causes the view (or one of its embedded text fields) to resign the first responder status."

"force: Specify YES to force the first responder to resign, regardless of whether it wants to do so. ReturnValue: YES if the view resigned the first responder status or NO if it did not."

[self.textField resignFirstReponder];

"Notifies the receiver that it has been asked to relinquish its status as first responder in its window"

Sending the -endEditing:(BOOL)force call to the view containing the input first responder will cause the text field to be sent a resign message, causing the on-screen keyboard to be dismissed.

resignFirstResponder removes the present first responder in the UIResponder hierarchy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top