I don't like to deal with tag so here is my solution. Create an IBOutletCollection of all your textFields in your ViewController, drag to connect your textFields in order from top to bottom.
@interface ViewController () <UITextFieldDelegate>
@property (strong, nonatomic) IBOutletCollection(UITextField) NSArray *allTextFields;
@end
In viewDidLoad set your textFields delegate. (Or set it in storyboard).
for (VVTextField *tf in self.allTextFields) {
tf.delegate = self;
}
Then implement UITextField Delegate
#pragma mark - UITextField Delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSUInteger currentIndex = [self.allTextFields indexOfObject:textField];
NSUInteger nextIndex = currentIndex+1;
if (nextIndex < self.allTextFields.count) {
[[self.allTextFields objectAtIndex:nextIndex] becomeFirstResponder];
} else {
[[self.allTextFields objectAtIndex:currentIndex] resignFirstResponder];
}
return YES;
}