I have multiple UITextField's and am trying to click next to switch between them. I have set the tags for each one from 1-4. When I run my code, it moves to the second one, but won't move to the third. If I jump textField.tag + 2; it will jump to the third field, but it doesn't move on from there. Here is my code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
theScrollView.frame = CGRectMake(theScrollView.frame.origin.x, theScrollView.frame.origin.y,
theScrollView.frame.size.width, theScrollView.frame.size.height + 265 - 50); //resize
NSInteger nextTag = textField.tag + 1;
// Try to find next responder
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
} else {
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return NO; // We do not want UITextField to insert line-breaks.
}
I would review the following items:
UITextField
objects have its delegate settextfield
's tagUIView
object returned in viewWithTag:
is actually a UITextField
object.