0

After looking at the examples provided by this previous question & answer... Switching between Text fields on pressing return key in Swift, i figured applying the function would be relatively seamless. However, after applying the code below, the switch to a new first responder is not working. I have the delegates set, the tags set, the function set and still no progress. I'm clearly missing something in this logic but can't seem to realize what it is.

    override func viewDidLoad() {
    super.viewDidLoad()

    self.Class1TF.delegate = self as? UITextFieldDelegate
    self.Credits1TF.delegate = self as? UITextFieldDelegate
    self.Grade1TF.delegate = self as? UITextFieldDelegate
    self.CumCredits.delegate = self as? UITextFieldDelegate
    self.CumGPA.delegate = self as? UITextFieldDelegate

    Class1TF.tag = 0
    Credits1TF.tag = 1
    Grade1TF.tag = 2
    CumCredits.tag = 3
    CumGPA.tag = 4

    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(Classes2Controller.dismissKeyboard))
    view.addGestureRecognizer(tap)

    func textFieldShouldReturn(_ textField: UITextField) -> Bool
    {
        // Try to find next responder
        if let nextField = textField.superview?.viewWithTag(textField.tag + 1) as? UITextField {
            nextField.becomeFirstResponder()
        } else {
            // Not found, so remove keyboard.
            Class1TF.resignFirstResponder()
            return true
        }
        // Do not add a line break
        return false
    }
Jon
  • 75
  • 1
  • 9

0 Answers0