sushibrain
sushibrain

Reputation: 2780

Textfield Delegate functions not called

I'm working on an app where there are multiple steps to go in a flow. I transformed the return key on all UItextfieldsinto a "next" button, and I hooked up the delegates like this:

override func viewDidLoad() {
    super.viewDidLoad()
    self.input.delegate = self
    setupRX()
}

I also implemented the following delegate method:

func textFieldShouldReturn(textField: UITextField!) -> Bool {
    textField.resignFirstResponder()
    print("did")
    if self.nextButton.isEnabled {
        print("did")
        self.performSegue(withIdentifier: "nextStep", sender: nil)
    }

    return true
}

However the above function never gets called... As far as I know, I check all the boxes; I set the delegate, I implemented UITextFieldDelegate and I made the method like it's supposed to be made.

Did I miss something or is this perhaps a bug?

Upvotes: 0

Views: 1301

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

Try this with underscore before textField

func textFieldShouldReturn(_ textField: UITextField!) -> Bool {
    textField.resignFirstResponder()
    print("did")
    if self.nextButton.isEnabled {
        print("did")
        self.performSegue(withIdentifier: "nextStep", sender: nil)
    }

    return true
}

Upvotes: 4

Related Questions