简体   繁体   English

iPhone中textfieldshouldendediting和textfieldDidendediting的区别

[英]Difference between textfieldshouldendediting and textfieldDidendediting in iPhone

textFieldShouldendEditingtextfieldDidEndEditing有什么区别,以及何时应该使用每个方法?

textFieldShouldEndEditing : 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. 通常,您将从此方法返回YES以允许文本字段重新签署第一个响应者状态。 You might return NO, however, in cases where your delegate detects invalid contents in the text field. 但是,如果您的委托在文本字段中检测到无效内容,则可能返回NO。 By returning NO, you could prevent the user from switching to another control until the text field contained a valid value. 通过返回NO,您可以阻止用户切换到另一个控件,直到文本字段包含有效值。

textFieldDidEndEditing : 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 site:apple.com textFieldShouldendEditing

textFieldShouldEndEditing textFieldShouldEndEditing

textFieldDidEndEditing textFieldDidEndEditing

on textFieldShouldendEditing : you should return BOOL value YES will resign responsder and NO will stay where it is textFieldShouldendEditing :你应该返回BOOL值YES将重新响应响应者而NO将保持在原来的位置

textfieldDidEndEditing will be fired when text field is after edit mode. 当文本字段在编辑模式之后,将触发textfieldDidEndEditing

as per Apple 按照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. 在文本字段重新启动其第一个响应者状态后调用此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM