问题描述
我为iPhone iOS 4和Xcode 4开发了一个项目。
I work on a project for iPhone iOS 4 and Xcode 4.
有一种方法可以知道用户是否修改了UITextField的文本?
There is a method to know if the text of a UITextField ha been modified by the user?
例如,我有2个UITextField,textFieldA和textFieldB,并假设textField包含一些文本为abc。
For example,I have 2 UITextField, textFieldA and textFieldB, and suppose that textField contains some text as "abc".
用户首先点击textFieldA(键盘打开),然后点击textFieldB。如何知道textFieldA中的文本是否已被用户修改?
The user first tap in textFieldA (keyboard opens), and then in textFieldB. How can I know if the text in textFieldA has been modified by the user?
谢谢。
推荐答案
如何:首先订阅头文件中的文本字段委托:
< UITextFieldDelegate>
How about: First subscribe to the text field delegate in your header file with:
<UITextFieldDelegate>
然后在您的实现文件(.m)中的某处,您可以添加:
myTextField.delegate = self;
Then somewhere in your implementation file (.m), you can add: myTextField.delegate = self;
现在,您可以访问文本字段的委托方法。这意味着您现在可以使用:
Now you can access the delegate methods for text fields. This means you can now use:
-(void)textFieldDidBeginEditing:(UITextField *)textField
和 - (void)textFieldDidEndEditing:(UITextField *)textField
为什么不在textFieldDidBeginEditing中存储文本字段的值,并将其与textFieldDidEndEditing中的值进行比较? `
Why not store the value of your text field in textFieldDidBeginEditing and compare it to it's value in textFieldDidEndEditing? `
这篇关于如何知道用户是否修改了UITextField的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!