Answer the question
In order to leave comments, you need to log in
[[+content_image]]
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;
-(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;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question