2010-10-22 2 views
1

J'ai une table avec 3 UITextFields ajoutés aux vues de contenu des cellules (1 ligne par section). J'ai une 4ème section que j'insère afin que je puisse faire défiler le champ particulier pour être au-dessus du clavier. Le problème que j'ai (sur l'iPad seulement) est que quand l'un des champs de texte a firstResponder, il ne renonce pas quand l'utilisateur appuie sur un autre champ. Y a-t-il des différences dans la chaîne du répondeur sur un ipad? Dans le code ci-dessous pour mes contrôleurs de vue UITextFieldDelegate - textFieldShouldEndEditing n'est pas appelé lorsque vous touchez un autre champ. Appuyer sur le bouton Terminé fonctionne comme prévu (sauf si un autre champ a été touché).Répondeur qui ne démissionne pas de l'iPad

Un problème avec le code ci-dessous?

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    if (!_editing++) { 
     [self.tableView insertSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone]; 
    } 

    // scroll to section number in the text fields tag 
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:textField.tag] atScrollPosition:UITableViewScrollPositionTop animated:YES]; 

    return YES; 
} 

- (void) textFieldDidBeginEditing:(UITextField *)textField { 
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:textField action:@selector(resignFirstResponder)] autorelease]; 
} 

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField { 
    if (_editing-- == 1) { 
     // 
     [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone]; 
    } 

    self.navigationItem.rightBarButtonItem = nil; 

    // do something with the text here... 

    return YES; 
} 
+0

Eh bien je l'aurais écrit (! (--_ édition)) pour la cohérence, mais à part ça, pour le code de travail sur iPhone, ... – jv42

+0

ouais, son odd..app est seulement développé pour l'iPhone interface aussi, donc ipad en "mode iphone". Avoir réussi une solution de contournement en démissionnant de force le premier répondeur actuel dans textFieldShouldBeginEditing ... mais ce n'est pas parfait (le clavier ne reste pas allumé tout en changeant de champs - besoin d'appuyer deux fois sur le champ pour changer) –

Répondre

0

OK, j'ai trouvé une solution satisfaisante, il semble permettre la boucle d'exécution avant d'exécuter la demande d'animer la suppression d'une section résout le problème. Je suppose que c'est un bug de pomme? Pour tous ceux qui s'inquiètent de ce problème - je courais iOS3.2.1 sur l'iPad.

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField { 
    if (_editing == 1) { 
     [self performSelector:@selector(hideFinalSection) withObject:nil afterDelay:0.0f]; 
    } 
    else { 
     _editing--; 
    } 

    self.navigationItem.rightBarButtonItem = nil; 

     // do something with the text here... 

    return YES; 
} 

- (void) hideFinalSection { 
    if (!(--_editing)) { 
     [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone]; 
    } 
} 
Questions connexes