[[+content_image]]
I
I
Ilya2015-06-01 13:22:14
iOS
Ilya, 2015-06-01 13:22:14

How to implement transition to the next UITextField in the next UITableCell?

Welcome all.
Given: UIViewController. It has a sign with fields for registration.
In each line of the table, something like this UITextField is written

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;

Well, it's spelled out accordingly.
-(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;
}

The table will scroll with a bang. But the cursor does not move to the next UITextField. He, as it were, remains in the first (from which they entered)
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question