I have four UITextFields that I would like to use in a UIAlertView, Currently this is what it is looking like
What I would like to be able to do is restrict each box to 4 characters once each field once that 4 character limit is reached then I would like the next UITextField to become the first responder.
I would also like to be able to do this in reverse so if characters are being deleted once there are no characters available in the second field go to the first and start deleting etc.
Currently my code is pretty sloppy as I am just trying to get something like this working.. so this is what it looks like so far.
//prompt user to enter registration here UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Register Device" message:@" " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 53, 30)];
UITextField *myTextField1 = [[UITextField alloc] initWithFrame:CGRectMake(77, 45, 53, 30)];
UITextField *myTextField2 = [[UITextField alloc] initWithFrame:CGRectMake(142, 45, 53, 30)];
UITextField *myTextField3 = [[UITextField alloc] initWithFrame:CGRectMake(207, 45, 53, 30)];
// need to do something with first reasponder once 4 digits has been entered per box etc.
[myTextField becomeFirstResponder];
myTextField.placeholder =@"AAAA";
myTextField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
myTextField.textAlignment = NSTextAlignmentCenter;
myTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myTextField1.placeholder =@"AAAA";
myTextField1.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
myTextField1.textAlignment = NSTextAlignmentCenter;
myTextField1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myTextField2.placeholder =@"AAAA";
myTextField2.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
myTextField2.textAlignment = NSTextAlignmentCenter;
myTextField2.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myTextField3.placeholder =@"AAAA";
myTextField3.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
myTextField3.textAlignment = NSTextAlignmentCenter;
myTextField3.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myTextField1 setBackgroundColor:[UIColor whiteColor]];
[myTextField2 setBackgroundColor:[UIColor whiteColor]];
[myTextField3 setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert addSubview:myTextField1];
[alert addSubview:myTextField2];
[alert addSubview:myTextField3];
[alert show];
Any help would be greatly appreciated.
// UPDATE: this is how I am trying to use the delegate method
//.h
<UITextFieldDelegate>
//.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//..
[self.myTextField setDelegate:self];
[self.myTextField1 setDelegate:self];
[self.myTextField2 setDelegate:self];
[self.myTextField3 setDelegate:self];
//..
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSLog(@"yay");
return NO;
}