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

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

    I got an issue that password textfield get focus and then lose focus immediately. At last I found that we'd better return NO in function textFieldShouldReturn:. If we return YES, the text field will get a insertText: call. Then it will lose focus. Don't know the reason.

    I have created a new question for this issue: UITextField get focus and then lose focus immediately due to return YES in textFieldShouldReturn

    If anyone knows the reason, please let me know. Thanks.

    - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
        if (theTextField == self.textPassword) {
            [theTextField resignFirstResponder];
        } else if (theTextField == self.textUsername) {
            [self.textPassword becomeFirstResponder];
        }
        // we'd better return NO here
        return NO;
    }
    

提交回复
热议问题