@postnik

Как реализовать переход на следующий UITextField в следующий UITableCell?

Приветствую всех.
Дано: UIViewController. В нем табличка с полями для регистрации.
В каждую строчку таблицы пишется примерно такой UITextField
UITextField * emailField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, self.view.frame.size.width-40, 30)];
            emailField.placeholder = @"Email";
            emailField.backgroundColor = [UIColor whiteColor];
            emailField.layer.borderColor = [[UIColor grayColor]CGColor];
            emailField.layer.cornerRadius = 7.0;
            emailField.tag = 201;
            emailField.delegate = self;
            emailField.keyboardType = UIKeyboardTypeEmailAddress;
            emailField.returnKeyType = UIReturnKeyNext;
            emailField.textAlignment = NSTextAlignmentCenter;


Ну и соответственно прописано
-(BOOL)textFieldShouldReturn:(UITextField*)textField
{
    NSInteger nextTag = textField.tag + 1;
    UITableViewCell * currentCell = (UITableViewCell *) textField.superview.superview;
    NSIndexPath * currentIndexPath = [self.regTable indexPathForCell:currentCell];
    
    if (currentIndexPath.row != 4) {
        
        NSIndexPath * nextIndexPath = [NSIndexPath indexPathForRow:currentIndexPath.row + 1 inSection:0];
        UITableViewCell * nextCell = (UITableViewCell *) [self.regTable cellForRowAtIndexPath:nextIndexPath];
        
        [self.regTable scrollToRowAtIndexPath:nextIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        
        UITextField *nextResponder = (UITextField *)[self.view viewWithTag:nextTag];
        [nextResponder becomeFirstResponder];
    }
    
    
    return YES;
}


Таблица скролится на ура. Но не происходит переход курсора в следующий UITextField. Он как бы остается в первом(с которого зашли)

Спасибо.
  • Вопрос задан
  • 218 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы