UiTableView mit Textfeldern scrollen wenn die Tastatur erscheint

Ich bin erstellen Sie ein Formular mit Textfeldern in einem tableview-controller. Ich bin versucht, 2 Dinge erreichen hier, wenn die Taste "return" nach der Eingabe-Wert für ein Feld:

1) Bewegen Sie den cursor zum nächsten Feld
2) Scrollen Sie in der tableview bis

Mein code funktioniert für das bewegen des Cursors in das nächste Feld, aber das scroll-Teil nicht funktioniert. Könnten Sie lassen Sie mich wissen, was ich hier vermisst. Ich habe ähnliche Fragen auf stack overflow und bin nach Anregungen von Ihnen aber immer noch Probleme. Schätzen Sie Ihre Eingaben.

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    if ([textField isEqual:self.firstName]){
    //Move cursor to next field
    [self.lastName becomeFirstResponder];

    //scroll    
    id cellContainingFirstResponder = textField.superview.superview ;
    NSIndexPath *currentRowIndexPath = [self.signUpTable indexPathForCell:cellContainingFirstResponder];
    NSIndexPath *nextRowIndexPath = [NSIndexPath indexPathForRow:currentRowIndexPath.row+1 inSection:currentRowIndexPath.section];
    [self.signUpTable scrollToRowAtIndexPath:nextRowIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

if ([textField isEqual:self.lastName]){
    //Move cursor to next field
    [self.emailId becomeFirstResponder];

    //scroll
    id cellContainingFirstResponder = textField.superview.superview ;
    NSIndexPath *currentRowIndexPath = [self.signUpTable indexPathForCell:cellContainingFirstResponder];
    NSIndexPath *nextRowIndexPath = [NSIndexPath indexPathForRow:currentRowIndexPath.row+1 inSection:currentRowIndexPath.section];
    [self.signUpTable scrollToRowAtIndexPath:nextRowIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

if ([textField isEqual:self.emailId]){

    //Move cursor to next field
    [self.phoneNumber becomeFirstResponder];

    //scroll
    id cellContainingFirstResponder = textField.superview.superview ;
    NSIndexPath *currentRowIndexPath = [self.signUpTable indexPathForCell:cellContainingFirstResponder];
    NSIndexPath *nextRowIndexPath = [NSIndexPath indexPathForRow:currentRowIndexPath.row+1 inSection:currentRowIndexPath.section];
    [self.signUpTable scrollToRowAtIndexPath:nextRowIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

if ([textField isEqual:self.phoneNumber]){

    //Move cursor to next field
    [self.password becomeFirstResponder];

    //scroll
    id cellContainingFirstResponder = textField.superview.superview ;
    NSIndexPath *currentRowIndexPath = [self.signUpTable indexPathForCell:cellContainingFirstResponder];
    NSIndexPath *nextRowIndexPath = [NSIndexPath indexPathForRow:currentRowIndexPath.row+1 inSection:currentRowIndexPath.section];
    [self.signUpTable scrollToRowAtIndexPath:nextRowIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

}

//This is the last field hence dismiss keyboard -> This part is working
if ([textField isEqual:self.password]){
    [textField resignFirstResponder];

}

return YES ;

}
  • Das ist, weil Ihr ContentSize ist nicht Groß Genug, Versuchen und erhöhen Ihre UITableView ContentSize.
InformationsquelleAutor Mike G | 2013-07-18
Schreibe einen Kommentar