iOS app “next” key won't go to the next text field

前端 未结 11 2537
栀梦
栀梦 2020-12-12 21:32

I have a simple scene (using storyboard in IB) with a Username and Password text box. I\'ve set the keyboard to close when you are on the Password text field but can\'t get

11条回答
  •  醉酒成梦
    2020-12-12 21:47

    I use this code that allows me to control the form behavior in the storyboard:

    -(BOOL) textFieldShouldReturn:(UITextField *)textField{
        if(textField.returnKeyType==UIReturnKeyNext) {
            UIView *next = [[textField superview] viewWithTag:textField.tag+1];
            [next becomeFirstResponder];
        } else if (textField.returnKeyType==UIReturnKeyDone) {
            [textField resignFirstResponder];
        }
        return YES;
    } 
    

    All you need is to assign the order value as tag, and returnkey according to Next or Done on each input control.

提交回复
热议问题