限制 UITextField 中的条目
有没有办法限制用户在 UITextField 中仅输入某些信息?例如,我想限制用户只能进入美国各州。我知道我可以使用其他控件,例如 UIPickerView,但如果可能的话,我希望他们键入此控件。谢谢。
Is there a way to restrict a user to enter only certain information inside a UITextField? For example, I want to restrict a user to enter only U.S. states. I know I can use other controls, such as UIPickerView, but I want them to type this, if possible. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看:
这是一篇关于给定可能值数组(NSMutableArray)的自动完成的文章。您可能可以稍微更改它以限制条目,而不是自动完成的建议。
http://www.raywenderlich.com/336/how -to-auto-complete-with-custom-values
希望有帮助。
check out:
Here's an article on autocomplete given an array of possible values (an NSMutableArray). You could probably change it slightly to limit the entries instead of suggestions for autocomplete.
http://www.raywenderlich.com/336/how-to-auto-complete-with-custom-values
Hope that helps.
UITextField 限制又受到某些限制。您可以限制文本字段仅接受字母、字母数字值或数字值。但限制文本字段接受除美国以外的其他国家的州名几乎是不可能的。
实现此目的的一种方法是拥有美国州名的字典/列表。当用户在文本字段中输入完文本后,将输入的文本与您拥有的列表进行匹配。如果列表不包含键入的文本,则该用户不是真实的,并且他试图欺骗您的应用程序。 :-0
最好的方法是让用户从 UIPickerView 或 UITableView 中选择您希望用户选择的状态名称。通过这种方式,用户受到完全限制,他无法欺骗您的应用程序。 ;-)
The UITextField restriction is in turn restricted to certain limits. You can restrict the text field to accept only the Alphabets, Alphanumeric values, or Numeric values. But its almost impossible to restrict text field from accepting State names of other countries but US.
One way you can do this is by having a dictionary/list of the State names in US. And when the user finished entering the text in the text field, match the entered text with the list you have. If the list doesn't contain the text typed, then the user is not genuine, and he is trying to cheat your app. :-0
The best way is to let the user pick from a UIPickerView or UITableView with the State names you want the user to pick from. By this way the user is completely restricted and no way he can cheat your app. ;-)