What is the approppriate way in iOS 7 to deal with text input field validation? Is there an alternative to showing the dialog?
I do not have much experience with iOS apps (I'm more of an android fan) and I would like it to be similar to android's:
mEditText.setError("Error string");
Closest thing I found is this library, but I would like to know if there is something native in iOS (if possible, I would like to avoid using 3rd party libs).
Thanks in advance.
I'm not aware of something as simple as the android example you mention. But once you have determined that a value is invalid as per @Herre_84, you have a few things you can do that don't involve bringing up an alert dialog.
A common thing to do is to use the UITextField
's overlay views to indicate that the value is in error. There are overlay views available to you on the left and the right sides of the UITextField
. You can put images in them that indicate the valid status of the input as in the answer to this question. More details are in the official Apple documentation.
Another less common thing you can do is use the attributedText
property of UITextField
to indicate that the text is not valid. For example, you could make incorrect text a different color. TSValidatedTextField
demonstrates how to do that.
Finally, you could use a completely separate view (perhaps appearing near your UITextField
) that you update with validity information. You'd have to wire up the two views, probably via a shared parent view controller, to effect the communication between them.
There is no standard or specific "iOS7" way of validating text. You could however implement your own "validation framework" (similar to the one you are pointing to in the link you added) by using UITextfield
's own delegate methods like
- (void)textFieldDidEndEditing:(UITextField *)textField
, which indicates that the user is done editing (eg when he dismissed the keyboard or pressed the "Done" button) - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
, which is triggered when when a new character is entered in the UITextField.Based on these events, you could evaluate the current NSString
in the UITextField
using it's text
property, and adapt your UI accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With