Difference between textfieldshouldendediting and textfieldDidendediting in iPhone

*爱你&永不变心* 提交于 2019-11-30 15:22:47

问题


What is the difference between textFieldShouldendEditing and textfieldDidEndEditing, and when should each method be used?


回答1:


textFieldShouldEndEditing:

Asks the delegate if editing should stop in the specified text field.

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField

Discussion This method is called when the text field is asked to resign the first responder status. This might occur when your application asks the text field to resign focus or when the user tries to change the editing focus to another control. Before the focus actually changes, however, the text field calls this method to give your delegate a chance to decide whether it should.

Normally, you would return YES from this method to allow the text field to resign the first responder status. You might return NO, however, in cases where your delegate detects invalid contents in the text field. By returning NO, you could prevent the user from switching to another control until the text field contained a valid value.

textFieldDidEndEditing:

Tells the delegate that editing stopped for the specified text field.

- (void)textFieldDidEndEditing:(UITextField *)textField

Discussion This method is called after the text field resigns its first responder status. You can use this method to update your delegate’s state information. For example, you might use this method to hide overlay views that should be visible only while editing. Implementation of this method by the delegate is optional.

site:apple.com textFieldShouldendEditing

textFieldShouldEndEditing

textFieldDidEndEditing




回答2:


on textFieldShouldendEditing: you should return BOOL value YES will resign responsder and NO will stay where it is

textfieldDidEndEditing will be fired when text field is after edit mode.

as per Apple

This method is called when the text field is asked to resign the first responder status.

This method is called after the text field resigns its first responder status.



来源:https://stackoverflow.com/questions/12262909/difference-between-textfieldshouldendediting-and-textfielddidendediting-in-iphon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!