-5

By this img with done btn to move at next textfield (https://i.stack.imgur.com/cDHlh.jpg)

  • 2
    Welcome to Stack Overflow. Please spend a few minutes taking the [tour] and reading the [help] pages, particularly [ask], and then come back and [edit] your question. Thanks. – Ken White Oct 13 '17 at 16:59
  • as a beginner please explain your question as much as possible. For your question uitextfield has a method 'becomeFirstResponder' so on button action you have to put [yourTextField becomeFirstResponder] – Gagan_iOS Oct 13 '17 at 17:06
  • Please check https://stackoverflow.com/questions/31766896/switching-between-text-fields-on-pressing-return-key-in-swift – Vini App Oct 13 '17 at 21:55

1 Answers1

-1

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

    class VC: UIVIewController, UITextFieldDelegate
    
  2. In your ViewDidLoad method do this -

    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. 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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Yash Tamakuwala
  • 1,789
  • 1
  • 24
  • 33