gpt4 book ai didi

validation - Monotouch 用户输入数据验证

转载 作者:行者123 更新时间:2023-12-02 20:53:54 24 4
gpt4 key购买 nike

使用单点触控如何验证用户输入的数据?我正在为我的 iPhone 应用程序创建一个简单的联系表单。

在 asp.net 中,我可能会使用验证摘要来显示验证消息和必填字段,或根据正则表达式检查电子邮件地址输入。

但是,对于 iPhone,我认为当用户在 UITextField 中输入一些数据时,我可以在触摸事件上验证该用户,然后在警报对话框中显示验证消息?

如何使我的窗口表单以这种方式验证?

最佳答案

我认为这就是你这样做的方式:

子类UITextFieldDelegate。覆盖ShouldEndEditing()。验证用户在 ShouldEndEditing() 中输入的数据。如果数据无效,则创建并显示一个 UIAlertView 解释数据无效的原因,并从 ShouldEndEditing() 返回 false (或使用其他一些表示存在问题的信号)。如果数据有效,则返回true。将 UITextFieldDelegate 子类对象分配给 UITextField 对象的 Delegate 属性。

释义 Apple 文档:

This method [ShouldEndEditing()] 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 "true" from this method to allow the text field to resign the first responder status. You might return "false," however, in cases where your delegate detects invalid contents in the text field. By returning "false," you could prevent the user from switching to another control until the text field contained a valid value.

关于validation - Monotouch 用户输入数据验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5780964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com