检测用户是否键入了UITextField [英] Detecting whether the user has typed in a UITextField

查看:85
本文介绍了检测用户是否键入了UITextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如果您使用以下代码行,您可以检测用户在文本视图中输入的内容。

I know that if you use the following line of code, you can detect what the user has typed in a TEXT VIEW.

if ([[textView text] isEqualToString:@"")

我想检测是否用户在文本FIELD中键入了任何内容,这不适用于文本字段。我应该改变什么?谢谢你的帮助!

I want to detect whether the user has typed anything in a text FIELD, and this does not work with text fields. What should I change? Thanks for your help!

推荐答案

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

这篇关于检测用户是否键入了UITextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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