I'm learning iOS development and am having a hard time figuring out the various events for the controls. For a test I have a UITextField where the user is meant to input a string in the format: XXXX-XXXX-XXXX-XXXX
I want to be able to check how long the text in the field is after each entry and see if it needs to have a hyphen appended to it. I've set up my IBAction function for this but when I assign it to the "Value Changed" event it does nothing, it works fine when I set it on the "Editing Did End" but that will only call when the user exits the control.
Edit: Just to add, the "Editing Changed" event causes it to crash too. I assume this is a stack overflow or something where the setting of the text calls the event handler again.
So in short, is there any way to set an event handler for each time the user enters a character in the UITextField?
You could try this:
It should really work with that, you should also post some code. After registering with the event you should just check the lenght of the string and add hyphen.
For something like this I would suggest using the UITextFieldDelegate to detect whenever the user types a new character. Setup your text field's delegate as follows:
Then, implement the delegate methods as appropriate:
This may not work perfectly, but I hope it helps!