I want the firstResponder to go to the previous TextField when the back or return key is pressed. But the textFieldShouldReturn does not get launched. Many thanks guys!
Tried this but it doesn't seem to work.
MyViewController.h
@interface MyViewController : UIViewController <UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *firstCodeField;
MyViewController.m
@synthesize firstCodeField;
- (void)viewDidLoad
{
[super viewDidLoad];
firstCodeField.delegate = self;
secondCodeField.delegate = self;
thirdCodeField.delegate = self;
fourthCodeField.delegate = self;
fifthCodeField.delegate = self;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSUInteger newLength = [textField.text length] + [string length] - range.length;
if (string.length == 0 && textField.text.length)
{
if(textField==fifthCodeField) {
NSLog(@"It goes to fourth textfield but doesn't clear the number in the cell.");
[textField resignFirstResponder];
[fourthCodeField becomeFirstResponder];
return NO;
}
}
return (newLength > 1) ? NO : YES;
}