且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测用户是否键入了UITextField

更新时间:2022-01-28 09:38:10

UITextFieldDelegate 是找到它的首选方式。

The UITextFieldDelegate is the preferred way to find this out.

- (void)textFieldDidBeginEditing:(UITextField *)textField - 这只会告诉你它已成为第一个响应者/密钥字段,这并不保证用户修改了值

- (void)textFieldDidBeginEditing:(UITextField *)textField - this will only tell you that it has become the first responder / key field, this does not guarantee that the user modified the value

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)范围replacementString:(NSString *)string - 此方法会告诉您用户何时按键更改文本,粘贴将导致多个字符位于字符串中,退格覆盖一个,或删除选择将导致字符串为空,...

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string - this method will tell you when ever the user hits a key to change the text, a "paste" will cause multiple characters to be in the string, backspace over one, or delete of a selection will cause the string to be empty, …

- (void)textField DidEndEditing:(UITextField *)textField - 这是一个常用位置,用于根据模型中的值检查字段中的值,以查看是否发生了编辑。这只会在字段放弃关键状态时调用,请注意,用户可以点击按钮以使整个视图在调用之前消失,通常可以跟踪您感兴趣的任何字段是否成为关键字段(参见第一种方法)

- (void)textFieldDidEndEditing:(UITextField *)textField - this is a common location to check the value in the field against the value in the model to see if an edit has occurred. this will only be called when the field relinquishes "key" status, note that a user could tap a button to cause the whole view to go away before this is called, often making it useful to track if any field you are interested in becomes the "key field" (see first method)

在相关实现中设置断点以熟悉其调用顺序/逻辑

it can be useful to set break points in relevant implementations to familiarize yourself with their call order/logic