Difference between textfieldshouldending and textfieldDidenditing in iPhone

Possible duplicate:
Difference between textfieldshouldending and textfieldDidenditing in iPhone

What is the difference between textFieldShouldendEditing and textfieldDidEndEditing ? and when they will use these methods.

+1
source share
3 answers

From the documentation:

 textFieldShouldendEditing: 

This method is called when the text field is prompted to reset the status of the first responder. This can happen when your application requests a text box to cancel focus or when the user tries to change the editing focus to another control. However, before the focus really changes, the text box calls this method to give your delegate the opportunity to decide if he should.

 textfieldDidEndEditing: 

This method is called after the text field leaves its first responder status. This method can be used to update delegate status information. For example, you can use this method to hide overlay views that should only be visible during editing.

So, the textFieldShouldendEditing: method will be called before the textfieldDidEndEditing: method

+2
source

textFieldShouldendEditing will call when your text screen finishes editing. It has a return type of BOOL. If you set return NO , than your textField will not be resignFirstResponder and will remain in edit mode, and textfieldDidEndEditing will not be called.

while textfieldDidEndEditing is a method that tells you that your text field is not in edit mode and your keyboard is not working.

See PLZ UITextFieldDelegate Protocol for more details. Hope this helps :)

+1
source

textFieldDidEndEditing: called when the text field resigns as the first responder. This way you can get the entered value from the user.

textFieldShouldendEditing: used to check whether the key entered by the user should be displayed in the text field or not. Therefore, if you return NO, the key is not displayed. Imagine a shortcut in which you want to limit the number of letters entered. You can use the above to check how many characters are entered, and if they have reached the limit, return a value of NO , which basically does not take any new strokes.

You can check the reference document for more information.

+1
source

Source: https://habr.com/ru/post/924533/


All Articles