Je suis en train de faire une application Coredata dans laquelle on m'a demandé de faire une vue de table (remplir un formulaire) avec un champ de texte dans chaque rangée que j'ai fait avec succès. Ensuite, j'ai créé une barre d'outils avec le bouton précédent et suivant et je l'ai ajouté à la commande inputAccsoryView de textField pour naviguer entre les champs de texte de chaque cellule. Un champ de texte par ligne. Je suis également capable de faire de la magie avec les méthodes de boutons précédent et suivant. Maintenant le problème:naviguer entre les champs de texte de uitableview
Supposons que j'ai 3 sections. Dans la première section 4 lignes. Dans la deuxième section 6 lignes et dans la dernière section 1 rangée. Maintenant, quand je commence à partir de la 1ère rangée et appuie sur la prochaine jusqu'à la 11ème rangée, il fonctionne correctement, mais je presse ensuite rien ne se passe comme la première rangée est déqueue je reçois "nul" pour cela. Le code J'utilise:
configuration de la cellule
if (cell == nil) {
NSLog(@"tag inside:%i",tag);
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:identifier] autorelease];
UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(120, 10, 170, 25)];
theTextField.textAlignment = UITextAlignmentRight;
theTextField.delegate = self;
theTextField.tag = tag;
theTextField.inputAccessoryView = [self configureTheToolBar];
[theTextField setKeyboardAppearance:UIKeyboardAppearanceAlert];
[cell.contentView addSubview:theTextField];
[theTextField release];
}
cell.textLabel.text = rowLabel;
UITextField *textField = (UITextField *)[cell.contentView viewWithTag:tag];
textField.text = rowValue
Je fournirai des tags pour textfield comme 601, 602 etc.
ensuite obtenir l'étiquette currentTextField
- (void)textFieldDidBeginEditing:(UITextField *)textField{
currentTextField = textField.tag;
}
alors la méthode suivante
if(currentTextField == 611){
currentTextField = 601;
} else{
currentTextField = currentTextField + 1;
}
NSLog(@"current text fiedld = %i",currentTextField);
NSLog(@"text ; %@",[self cellForTag:currentTextField].textLabel.text);
UITextField *firstResponderField = (UITextField *) [[self cellForTag:currentTextField].contentView viewWithTag:currentTextField];
[firstResponderField becomeFirstResponder];
et la méthode cellForTag:
-(UITableViewCell *)cellForTag:(NSInteger)tag{
UITableViewCell *cell;
switch (tag) {
case 601:{
NSUInteger onlyRow[] = {0, 0};
NSIndexPath *onlyRowPath = [NSIndexPath indexPathWithIndexes:onlyRow length:2];
//[self.tableView scrollToRowAtIndexPath:onlyRowPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
cell = [self.tableView cellForRowAtIndexPath:onlyRowPath];
break;
}
return cell
ce code fonctionne en partie comme une fois de cellules d'écran obtenir hors de la mémoire, je ne peux pas atteindre le champ de texte dans cette cellule et le bouton suivant cesse de fonctionner jusqu'à la valeur currentTextfield atteint n'importe quel visiblerow. Quelle pourrait être la solution. ma pile est écoulée. :)
Ok fil this fait le tour, mais je ne sais pas comment. quelqu'un peut-il m'expliquer comment?