No me gusta tratar con la etiqueta así que aquí está mi solución. Cree un IBOutletCollection
de todos sus textFields en su ViewController
, arrastre para conectar sus textFields en orden de arriba hacia abajo.
@interface ViewController() <UITextFieldDelegate>
@property (strong, nonatomic) IBOutletCollection(UITextField) NSArray *allTextFields;
@end
En viewDidLoad establezca su delegado textFields. (O configurarlo en el guión gráfico).
for (VVTextField *tf in self.allTextFields) {
tf.delegate = self;
}
luego implementar UITextField Delegado
#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;
}
Para marcar una respuesta como correcta, simplemente haga clic en el icono de marca de verificación vacía junto a la respuesta ... .. –