Search code examples
swiftuikit

How to distinguish between multiple textField returns?


I'm a bit inexperienced in regards to UIKit..

So I have multiple UITextField :

let companyTF = JobTextField(placeholder: "Company")
let positionTF = JobTextField(placeholder: "Position")
let hiringManagerTF = JobTextField(placeholder: "Hiring Manager")
let typeTF = JobTextField(placeholder: "Type")

Of course I had to make the parent VC conform to the delegate

extension JobAddVC: UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        print("Hello")
        return true
    }
}

Unfortunately that same code will run for every text field of this delegate class..

What is the solution here? Thanks


Solution

  • you need to compare textfield in delegate method

    eg.

    suppose your first textfield name is compantTextfield(Outlet bind name)

    if textfield == compantTextfield {
    print("Hello")
    }