Dans la vue d'ajout/édition de l'application Contacts, si vous appuyez sur la touche "Retour" dans un champ, vous parcourez chacun des UITextField. Ces champs semblent être dans un UITableViewCell. Quel est un bon moyen de le faire?Naviguer entre UITextFields dans UITableViewCell
Lorsque j'ai une série de UITextFields non à l'intérieur d'une table, je peux appeler [self.view viewWithTag:tag]
pour obtenir une liste des vues et l'utilisation qui permet de les parcourir. Mais dans une table, je n'ai qu'une vue et je ne sais pas trop comment la convertir.
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
// Find the next entry field
for (UIView *view in [self entryFields]) {
if (view.tag == (textField.tag + 1)) {
[view becomeFirstResponder];
break;
}
}
return NO;
}
/*
Returns an array of all data entry fields in the view.
Fields are ordered by tag, and only fields with tag > 0 are included.
Returned fields are guaranteed to be a subclass of UIResponder.
From: http://iphoneincubator.com/blog/tag/uitextfield
*/
- (NSArray *)entryFields {
if (!entryFields) {
self.entryFields = [[NSMutableArray alloc] init];
NSInteger tag = 1;
UIView *aView;
while (aView = [self.view viewWithTag:tag]) {
if (aView && [[aView class] isSubclassOfClass:[UIResponder class]]) {
[entryFields addObject:aView];
}
tag++;
}
}
return entryFields;
}