简体   繁体   English

如何在swift3 ios中使用键盘返回键将一个文本字段移动到另一个文本字段

[英]How to move one text field to another using keyboard return key in swift3 ios

通过此 img 与 done btn 移动到下一个文本字段( https://i.stack.imgur.com/cDHlh.jpg

I doubt if you can do that with the 'Done' button, but you may achieve that with the return key by我怀疑您是否可以使用“完成”按钮来做到这一点,但是您可以使用返回键来实现

  1. Make your class a UITextField Delegate让你的班级成为 UITextField 委托

    class VC: UIVIewController, UITextFieldDelegate
  2. In your ViewDidLoad method do this -在您的 ViewDidLoad 方法中执行此操作 -

     textField1.becomeFirstResponder()

So that when user comes in this screen the 1st textfield will directly become active(not the right word but using this word for lack of better alternative)因此,当用户进入此屏幕时,第一个文本字段将直接变为活动状态(不是正确的词,但由于缺少更好的选择而使用此词)

  1. And when you need it to move to the next textfield when he presses return,当你需要它在他按下回车键时移动到下一个文本框时,

     func textFieldShouldReturn(textField: UITextField) -> Bool { textField1.resignFirstResponder() if (textField == textField1){ textField2.becomeFirstResponder() } else if (textField == textField2){ textField3.becomeFirstResponder() } return true }

You may use a switch case too in the above delegate method.您也可以在上述委托方法中使用 switch case。 And as mentioned in the comment in the question, do go through the link and know how to properly ask questions, giving as much detail as possible.正如问题中的评论中所提到的,一定要浏览链接并知道如何正确提问,并提供尽可能多的细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift-文本字段键盘返回键不起作用? - Swift - Text Field Keyboard Return Key Not Working? 如何以编程方式在swift ios中自动将光标从一个文本字段移动到另一个文本字段? - How to move cursor from one text field to another automatically in swift ios programmatically? 如何在Swift iOS中将光标从一个文本字段自动移动到另一个文本字段? - How to move cursor from one text field to another automatically in swift ios? 当键盘显示时,Swift ios移动文本字段 - Swift ios move text field when keyboard is shown 我可以使用swift3 iOS在一个UIViewcotroller中设置ModelClass并从另一个UIViewCotroller中读取ModelClass的对象吗? - Can I set a ModelClass in one UIViewcotroller and read the ModelClass' object from another UIViewCotroller using swift3 iOS? 使用swift3在ios中单击时更改按钮上的文本 - changing the text on the button on clicking in ios using swift3 如何将文本写入swift3 iOS中保存在服务器上的文件中 - How to write text into the file saved on server in swift3 iOS swift3中文本字段上的文本视图消失 - Text view on text field disappear in swift3 如何在Swift3 iOS中使用Spotify获取歌曲列表? - How to get the list of songs using Spotify in Swift3 iOS? 如何在Swift3 iOS中使用Entity to POST创建JSON? - How to create JSON using Entity to POST in Swift3 iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM