문제

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:

  1. Check that all UITextField objects have its delegate set
  2. Start the debugger and inspect the value of every textfield's tag
  3. Make sure that there are no duplicate tags in the view hierarchy
  4. Test that the UIView object returned in viewWithTag: is actually a UITextField object.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top