iPhone中textfieldshouldendediting和textfieldDidendediting的区别 [英] Difference between textfieldshouldendediting and textfieldDidendediting in iPhone

查看:558
本文介绍了iPhone中textfieldshouldendediting和textfieldDidendediting的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

textFieldShouldendEditing textfieldDidEndEditing 之间的区别是什么?每个方法应该何时使用?

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

推荐答案

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.

通常,您将从此方法返回YES,以允许文本
字段重新签署第一个响应者状态。如果您的委托在
文本字段中检测到无效内容,则可以返回NO,
。通过返回NO,您可以阻止用户将
切换到另一个控件,直到文本字段包含有效值。

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

这篇关于iPhone中textfieldshouldendediting和textfieldDidendediting的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆