iOS应用“下一个”键不会转到下一个文本字段 [英] iOS app "next" key won't go to the next text field
问题描述
我有一个简单的场景(在IB中使用故事板),带有用户名和密码文本框。我在密码文本字段中设置键盘关闭但无法使用下一个(返回)按钮处理用户名以将焦点(或第一响应者)切换到密码文本框。
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 the next(return) button to work on the Username to switch the focus (or First Responder) to the Password text box.
我在密码文本字段上关闭键盘,如下所示:
I'm closing the keyboard while on the Password text field like this:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.textPassword) {
[theTextField resignFirstResponder];
}
return YES;
}
我知道它与此类似,但无法确定。
I know it is something similar to this but just can't nail it down.
推荐答案
默认情况下,返回键在文本字段中不做任何特殊操作。您需要明确更改第一个响应者:
The return key doesn't do anything special in a text field by default. You need to explicitly change the first responder:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.textPassword) {
[theTextField resignFirstResponder];
} else if (theTextField == self.textUsername) {
[self.textPassword becomeFirstResponder];
}
return YES;
}
这篇关于iOS应用“下一个”键不会转到下一个文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!