0

I have three textfields where the user enter their info. If the info format is not correct I will display a warning message in red color, then let them type in the new info. I tried to use a while loop to wait for their new info then go through the same if statements. If their new info is correct then once the button is pressed, we go to another storyboard. It didn't work for some reason. Can you tell me what I can do to display the warning message then wait for new input without going to the second storyboard just yet?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jackson Wang
  • 61
  • 1
  • 9

2 Answers2

2

While loop? No way!

What you are looking for is implementation of one of the following UITextFieldDelegate methods:

To put validation up-front as user type a character:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

To put validation once user is done typing:

- (void)textFieldDidEndEditing:(UITextField *)textField
- (BOOL)textFieldShouldReturn:(UITextField *)textField

Go through this Apple Documentation to understand it in detail.

Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • Thanks a lot! I am just starting to learn objective c and Xcode. Right now I'm taking an online course, could you recommend any books that might help me significantly? – Jackson Wang Sep 25 '15 at 17:18
  • I had recently suggested someone on this post http://stackoverflow.com/questions/32669622/learning-ios-programming-the-apple-way/32669743#32669743. Check if this help you. All the best! – Abhinav Sep 25 '15 at 22:35
0

sounds like this should solve your question: Listen to a value change of my text field Set a delegate for your field and have the delegate implement an onChange method where you validate the input.

Community
  • 1
  • 1
Joseph Duty
  • 775
  • 5
  • 14