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

前端 未结 11 2530
栀梦
栀梦 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:53

    I tried to use Esteve's answer but it doesn't work. Maybe because I'm using xib files. What I've done is change his code to make it works in my code.

    It works in the same way. All you need is to assign the order value as tag, and return key according to Next or Done or Send on each input control.

    - (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
        [textField resignFirstResponder];
    
        if(textField.returnKeyType==UIReturnKeyNext) {
    
            UITextField *next = (UITextField *)[self.view viewWithTag:textField.tag+1];
            [next becomeFirstResponder];
    
        } else if (textField.returnKeyType==UIReturnKeySend) {
    
            //Do whatever you want with the last TextField
        }
    
        return YES;
    }
    

提交回复
热议问题