I would like to create a pin-code dialogue, like the one you can switch on on the iPhone.
For those who have not seen it, it consists of four boxes and a number keypad. When you enter a digit, a dot appears in the first box. And so forth. When you hit the delete button, the last dot is removed.
I have this set up as four UITextFields and in my delegate I listen to:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
[self performSelector:@selector(pickNext:) withObject:textField afterDelay:0.0];
return YES;
}
The pickNext: method will switch to the next UITextField, like this:
- (void)pickNext:(UITextField*)textField
{
switch ([textField tag]) {
case 1:
[pin2 becomeFirstResponder];
break;
case 2:
[pin3 becomeFirstResponder];
break;
case 3:
[pin4 becomeFirstResponder];
break;
case 4:
[textField resignFirstResponder];
break;
default:
break;
}
}
This actually works, but the problem for me is that the delete key does not produce any notification when the UITextField is already empty. So I have no way of moving to the previous UITextField.
So does anyone have a better sugestion of how to solve this problem. I'm thinking hidden textfield...??